是否有一个 RecyclerView 等价于 ListView 的transcriptMode alwaysScroll?

sjo*_*nes 4 android android-recyclerview

使用 ListView,我可以通过设置轻松实现自动滚动聊天视图:

android:transcriptMode="alwaysScroll"
Run Code Online (Sandbox Code Playgroud)

在它的 XML 中。RecyclerView 中是否有等价物?

http://developer.android.com/reference/android/widget/AbsListView.html#attr_android:transcriptMode

Dre*_*ale 5

RecyclerView 似乎没有那个选项。您必须手动滚动。做一些像......

notifyItemInserted(int posn);
recyclerView.smoothScrollToPosition(la.getItemCount()); // <= use this.
Run Code Online (Sandbox Code Playgroud)

也无效notifyItemInserted(int posn); 是最终的。所以你不能覆盖它总是在那里滚动。

您需要创建一个方法,您可以将类似于上述代码的内容作为包调用。

还要记住平滑滚动有点问题。如果你有很多元素(例如 1000 个元素)并且你想滚动很长的距离,滚动需要永远。我发现有一个教程解决了这个问题,并解释了如何解决这个问题。http://blog.stylingandroid.com/scrolling-recyclerview-part-1/

享受,

  • 不是`la.getItemCount() - 1`? (4认同)