shenbengit / PagerGridLayoutManager

基于RecyclerView实现网格分页LayoutManager——PagerGridLayoutManager

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

可以知道当前正在显示的元素是哪些吗

LxzBUG opened this issue · comments

比如有两页,翻到第二页的时候,有个回调通知当前可见的item是哪个,不可见的是哪些

这个需求可以自己实现,回调当前页面的页数的时候,自己计算。

每页6个数据的话,currentPagerIndex ==1的时候,就是0-5正在显示,其他都是不可见。currentPagerIndex=2时,就是6-11。是这个思路去写吗

对,还要考虑不满一页的情况

`
public List getPage(List list, int pageIndex) {
int pageSize = 6; // 每页元素个数
int fromIndex = (pageIndex - 1) * pageSize; // 当前页起始元素下标
if (fromIndex >= list.size()) {
return new ArrayList(); // 当前页无元素,返回空列表
}
int toIndex = Math.min(fromIndex + pageSize, list.size()); // 当前页结束元素下标
return list.subList(fromIndex, toIndex); // 返回当前页元素列表
}

`

可以了

RecyclerView's width and height must be exactly

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_list"
android:layout_width="match_parent"
android:layout_height="450dp"
android:layout_centerInParent="true"
android:background="@android:color/transparent" />

        指定了宽高还是崩溃了

RecyclerView的父布局是什么?