shenbengit / PagerGridLayoutManager

基于RecyclerView实现网格分页LayoutManager——PagerGridLayoutManager
MIT License
244 stars 26 forks source link

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

Closed LxzBUG closed 1 year ago

LxzBUG commented 1 year ago

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

shenbengit commented 1 year ago

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

LxzBUG commented 1 year ago

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

shenbengit commented 1 year ago

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

LxzBUG commented 1 year ago

` 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); // 返回当前页元素列表 }

`

可以了

LxzBUG commented 1 year ago

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" />

        指定了宽高还是崩溃了
shenbengit commented 1 year ago

RecyclerView的父布局是什么?