在 RecyclerView 网格中放置一个不确定的进度条作为页脚 [英] Put an indeterminate progressbar as footer in a RecyclerView grid
问题描述
如何在网格 RecycleView 中为向上滚动加载更多"获取不确定的圆形指示器?
How to get indeterminate circular indicator for "Scroll up to load more" in a grid RecycleView?
模式在那里描述:http://www.google.com/design/spec/components/progress-activity.html#progress-activity-behavior 在两阶段加载"和示例 2:向上滚动以加载更多"示例视频中.
The pattern is described there: http://www.google.com/design/spec/components/progress-activity.html#progress-activity-behavior in "Two-phased loads" and "Example 2: Scroll up to load more" example videos.
我正在尝试使用新的 RecyclerView 来实现这一点,但我找不到一种不太黑客"的方法来做到这一点,首先是因为没有办法添加覆盖整行的页脚在网格中.有什么建议吗?
I'm trying to accomplish this using the new RecyclerView, but I can't find a "not-too-hackish" way to do that, firstly because there is not a way to add a footer that cover a full row in the grid. Any suggestions?
推荐答案
这样做很简单.
解决方案是使用 LinearLayoutManager
和 GridLayoutManager
的相同方法,然后在 LayoutManager 上使用方法
setSpanSizeLookup
像这样:
The solution is to use the same approach of the LinearLayoutManager
with a GridLayoutManager
and then use the method setSpanSizeLookup
on the LayoutManager
like this:
mLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
switch(myAdapter.getItemViewType(position)){
case MyAdapter.VIEW_TYPES.Product:
return 1;
case MyAdapter.VIEW_TYPES.Progress:
return 2; //number of columns of the grid
default:
return -1;
}
}
});
这将自动使该项目覆盖网格的一整行(如果该行不完全为空,则该项目进入下一行).
This will automatically make the item cover a full row of the grid (if the row is not totally empty this item goes to the next row).
这篇关于在 RecyclerView 网格中放置一个不确定的进度条作为页脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!