如何以编程方式滚动水平RecyclerView? [英] How to scroll horizontal RecyclerView programmatically?

查看:504
本文介绍了如何以编程方式滚动水平RecyclerView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个水平RecyclerView 和两个按钮(下一页,previous),如下图所示。

I have a horizontal RecyclerView and two button (Next,Previous) as shown in the image below.

在这里输入的形象描述

所以我需要通过使用移动到下一个项目或位置的这些按钮,我知道调用的方法 scrollTo ,但我不知道它是如何工作

so i need to move to the next item or position by use these buttons , i know about method called scrollTo but i don't know how does it work

推荐答案

RecyclerViews 有其暴露滚动到一定位置的方法:

RecyclerViews have a methods which they expose for scrolling to a certain position:

捕捉滚动到指定位置:

mRecyclerView.scrollToPosition(int position)

平滑滚动到指定位置:

mRecyclerView.smoothScrollToPosition(int position)

有关这些方法的工作,的LayoutManager 的需要已实施这些方法的 RecyclerView LinearLayoutManager 在做一个基本的方式实现这些,所以你应该是好去。

For these methods to work, the LayoutManager of the RecyclerView needs to have implemented these methods, and LinearLayoutManager does implement these in a basic manner, so you should be good to go.

这篇关于如何以编程方式滚动水平RecyclerView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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