问题描述
使用ListView,我可以通过设置轻松实现自动滚动聊天视图:
With ListView, I could easily implement an auto-scrolling chat view by setting:
android:transcriptMode="alwaysScroll"
XML中的
. RecyclerView是否具有等效功能?
in its XML. Is there an equivalent in RecyclerView?
http://developer.android.com/reference/android/widget/AbsListView.html#attr_android:transcriptMode
推荐答案
RecyclerView似乎没有该选项.您必须手动滚动.做类似....
RecyclerView doesn't seem to have that option.You have to manually scroll.Do something like....
notifyItemInserted(int posn);
recyclerView.smoothScrollToPosition(la.getItemCount()); // <= use this.
也无效notifyItemInserted(int posn);是最终的.因此,您也不能始终滚动到该位置.
Also void notifyItemInserted(int posn); is final. So you can't Override that to always scroll there either.
您需要创建一种方法,可以在其中调用与上述代码类似的东西作为包.
You need to make a method where you can call something similar to the above code as bundles.
还请记住,平滑滚动有点像越野车.如果您有很多元素(例如1000个元素),并且想滚动很远的距离,那么滚动将永远耗费时间.我发现有一个教程可以解决此问题,并说明如何解决该问题. http://blog.stylingandroid.com/scrolling-recyclerview-part-1/
Also keep in mind smooth scroll is kinda buggy. If you have many elements(e.g. 1000 elements) and you want to scroll a long distance, the scroll takes forever. There's a tutorial I found that addresses this issue and explains how you can fix that. http://blog.stylingandroid.com/scrolling-recyclerview-part-1/
享受,
这篇关于是否存在一个与ListView的transcriptMode alwaysScroll等效的RecyclerView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!