问题描述
我想在我的recyclerview中添加项目,并相应地更新滚动条.
I want to add items to my recyclerview and that my scrollbar is updated accordingly.
这是我的RecyclerView:
Here is my RecyclerView :
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="300dp"
android:scrollbars="vertical"
android:scrollbarThumbVertical="@color/clear_grey"
android:fadeScrollbars="false"
/>
将元素添加到数据集中后,我正在调用
After adding an element to my dataset, I am calling
recyclerViewAdapter.notifyItemInserted(recyclerViewAdapter.getItemCount() - 1);
问题是,滚动条未更新:我必须触摸视图才能对其进行更新.
The problem is, the scrollbar is not updated : I have to touch the views for it to be updated.
我正在使用
recyclerViewAdapter.notifyDataSetChanged();
滚动条已更新,但是我不能使用此解决方案.(我需要能够从视图中选择文本,这对于notifyDataSetChanged是不可能的.)
The scrollbar is updated, but I can't use this solution. (I need to be able to select text from the views, which is impossible with notifyDataSetChanged.)
关于如何更新滚动条的任何想法吗?
Any ideas on how to update the scrollbar ?
推荐答案
结果是我将fixedSize设置为true:
Turns out I had set fixedSize to true :
recyclerView.setHasFixedSize(true);
感谢此 https://stackoverflow.com/a/40373122/2437227 ,我尝试了没有它,它起作用了.
And thanks to this https://stackoverflow.com/a/40373122/2437227,I tried without it and it works.
这篇关于Recyclerview notifyItemInserted不更新滚动条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!