如何以编程方式滚动到“回收者视图"的底部? [英] How to programmatically scroll to the bottom of a Recycler View?

查看:65
本文介绍了如何以编程方式滚动到“回收者视图"的底部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在单击按钮时滚动到回收站视图的底部,我该怎么做?

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..!!

这篇关于如何以编程方式滚动到“回收者视图"的底部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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