有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java 安卓 RecyclerView添加新项目将回收移至列表顶部

当我的RecyclerView滚动到RecyclerView的末尾时,我会向它添加一些项目。这是我的代码:

rc_products.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            if (ViewType == ViewTypes.Grid) {
                visibleItemCount = mLayoutManager.getChildCount();
                totalItemCount = mLayoutManager.getItemCount();
                pastVisiblesItems = mLayoutManager.findFirstVisibleItemPosition();

                if ((visibleItemCount + pastVisiblesItems) >= totalItemCount) {
                    if (taskrunning != null && taskrunning == false && loadmore) {
                        page = page + 1;
                        getProducts(page);
                    }
                }
            }
        }
    });

当它到达RecyclerView的末尾时,它会获得一些新数据并向我的适配器添加新项,下面是随后运行的代码:

if (productAdaper == null) {
    productAdaper = new MyAdapter2(Productha.this, items_products);
    ScaleInAnimationAdapter scaldeAdapter = new ScaleInAnimationAdapter(productAdaper);
    scaldeAdapter.setDuration(300);
    rc_products.setAdapter(scaldeAdapter);
} else {
    productAdaper.addAll(items_products);
}

它工作正常,也会向我的RecyclerView添加新项目,但添加新项目时,它会一直滚动到RecyclerView的顶部

当它添加新数据时,我如何防止它上升并使它保持在原来的位置


共 (0) 个答案