是否有一个 RecyclerView 等同于 ListView 的transcriptMode alwaysScroll? [英] Is there a RecyclerView equivalent to ListView's transcriptMode alwaysScroll?

查看:37
本文介绍了是否有一个 RecyclerView 等同于 ListView 的transcriptMode alwaysScroll?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 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/

享受,

这篇关于是否有一个 RecyclerView 等同于 ListView 的transcriptMode alwaysScroll?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆