recycleview获取最大y轴滚动距离
时间: 2023-09-12 12:10:20
浏览: 154

RecycleVIew自动循环滚动使用
Re[cycle](https://wenku.csdn.net/doc/6412b57cbe7fbd1778d43545?spm=1055.2569.3001.10083)rView获取最大y轴滚动距离的方法如下:
1.获取[layout](https://wenku.csdn.net/doc/645ca2e259284630339a3ca0?spm=1055.2569.3001.10083)[manager](https://wenku.csdn.net/doc/7a8wy5gaga?spm=1055.2569.3001.10083)。
```java
LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
2.获取RecyclerView的高度。
```java
int recyclerViewHeight = recyclerView.getHeight();
3.获取所有子项的高度之和。
```java
int [total](https://wenku.csdn.net/doc/31nmcu1yk4?spm=1055.2569.3001.10083)ItemHeight = layoutManager.getItem[count](https://wenku.csdn.net/doc/6401ac87cce7214c316ec2cc?spm=1055.2569.3001.10083)() * layoutManager.getItemViewLayoutId();
4.计算出最大y轴滚动距离。
```java
int maxScrollY = totalItemHeight - recyclerViewHeight;
最终得到的maxScrollY就是RecyclerView在y轴方向上可以滚动的最大距离。注意,如果RecyclerView的高度大于所有子项的高度之和,那么最大滚动距离为0。
阅读全文
相关推荐

















