如何以编程方式滚动水平RecyclerView?

编程入门 行业动态 更新时间:2024-10-25 19:31:16
本文介绍了如何以编程方式滚动水平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?

本文发布于:2023-11-11 17:56:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1579157.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:水平   方式   RecyclerView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!