在recyclerview中从末端设置堆栈,而不是从最后一个位置开始

问题描述

这是我的代码,它从底部显示recyclerview,但从最后一项不显示! 同样,当我通过adapter.onItemChange(position)更新项目时,我的recyclerview滚动到顶部!

private void initRecyclerView() {
         linearlayoutmanager layoutManager = new linearlayoutmanager(activity);
        layoutManager.setStackFromEnd(true);
        binding.recyclerView.setItemViewCacheSize(20);
        binding.recyclerView.setDrawingCacheEnabled(true);
        binding.recyclerView.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
        binding.recyclerView.setLayoutManager(layoutManager);
        binding.recyclerView.setAdapter(chatAdapter);

        binding.recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrolled(@NonNull RecyclerView recyclerView,int dx,int dy) {
                super.onScrolled(recyclerView,dx,dy);
                recyclerOffset = dy;
            }
         });

        //scroll recyclerview when keyboard opened or closed
        binding.recyclerView.addOnLayoutchangelistener((v,left,top,right,bottom,oldLeft,oldTop,oldRight,oldBottom) -> {
            if (bottom < oldBottom) {
                binding.recyclerView.postDelayed((Runnable) () ->
                        binding.recyclerView.scrollBy(0,oldBottom - bottom),100);
            }
        });

    }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)