Mo *_*del 2 android view gridlayoutmanager android-recyclerview
我正在尝试使用RecyclerView和GridLayoutManager实现类似于上图的布局,我尝试根据位置设置setSpanSizeLookup但是无法模仿上面的设计.
有人可以帮忙吗?
UPDATE

Nis*_*ant 10
private GridLayoutManager getGridLayoutManager() {
final GridLayoutManager manager = new GridLayoutManager(getActivity(), 6);
manager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
int index = postion % 5;
switch(index){
case 0: return 2;
case 1: return 2;
case 2: return 2;
case 3: return 3;
case 4: return 3;
}
}
});
return manager;
}
Run Code Online (Sandbox Code Playgroud)
保证金更新
public class SpacesItemDecoration extends RecyclerView.ItemDecoration {
private int space;
public SpacesItemDecoration(int space) {
this.space = space;
}
@Override
public void getItemOffsets(Rect outRect, View view,
RecyclerView parent, RecyclerView.State state) {
outRect.right = space;
outRect.bottom = space;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4336 次 |
| 最近记录: |