use*_*316 16 android scroll layout-manager android-recyclerview
我想在recyclelerview中按y方向滚动一定数量的像素.我知道有像scrollToPosition()或的方法scrollToPositionWithOffset().但是,那些并不符合我的需求.
我看到它LayoutManager提供了一种方法scrollVerticallyBy(int dy, RecyclerView.Recycler recycler, RecyclerView.State state).这听起来像我想要的.
我该如何使用它?什么是recycler和state?我没有在网上找到任何例子,所以有些代码会很有用.
rub*_*ees 10
我不知道scrollVerticallyBy,这看起来更像是一个内部方法RecyclerView.你是不是只是为了寻找方法scrollBy(int x, int y)和smoothScrollBy(int dx, int dy)?
从文档:
public void scrollBy(int x,int y)
移动视图的滚动位置.这将导致对onScrollChanged(int,int,int,int)的调用,并且视图将失效.
参数
x int:水平滚动的像素数量
y int:垂直滚动的像素数量
您可以使用如下方法:
recyclerView.scrollBy(0, 50); //Scroll 50 pixels down
recyclerView.scrollBy(0, -50); //Scroll 50 pixels up
Run Code Online (Sandbox Code Playgroud)
同样的道理smoothScrollBy.
| 归档时间: |
|
| 查看次数: |
6889 次 |
| 最近记录: |