本文介绍了如何以编程方式滚动到“回收者视图"的底部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在单击按钮时滚动到回收站视图的底部,我该怎么做?
I want to scroll to the bottom of a recycler view on click of a button, how do I do this?
推荐答案
您必须为此使用LayoutManager
.请执行以下步骤.
You have to make use of LayoutManager
for that. Follow the below steps.
1).首先,在Activity/Fragment
中声明LayoutManager
.例如,我采用了LinearLayoutManager
1). First of all, declare LayoutManager
in your Activity/Fragment
. For example, I have taken LinearLayoutManager
private LinearLayoutManager mLinearLayoutManager;
2).初始化LinearLayoutManager
并将其设置为您的RecyclerView
2). Initialise the LinearLayoutManager
and set that to your RecyclerView
mLinearLayoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(mLinearLayoutManager);
3).在Button onClick
上,执行此操作以滚动到RecyclerView
的底部.
3). On your Button onClick
, do this to scroll to the bottom of your RecyclerView
.
mLinearLayoutManager.scrollToPosition(yourList.size() - 1); // yourList is the ArrayList that you are passing to your RecyclerView Adapter.
希望这会有所帮助.. !!
Hope this will help..!!
这篇关于如何以编程方式滚动到“回收者视图"的底部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!