Gridview: Gridview With Different Cells Sizes And Layout,
Hi I need a gridview which have 2 different layout in grid cells according to grid cell type.here is I am giving the example scrren drawn on paper.
Solution 1:
User RecyclerView
with GridLayoutManager
that have set SpanSizeLookup
. So it will be as follows:
intfullSpanSize=3;
intnormalSpanSize=1;
GridLayoutManagerlayout=newGridLayoutManager(context, fullSpanSize);
layout.setSpaneSizeLookup(newGridLayoutManager.SpanSizeLookup() {
@OverridepublicintgetSpanSize(int position) {
returnposition== 3 ? fullSpanSize : normalSpanSize;
}
});
recyclerView.setLayoutManager(layout);
Solution 2:
You can use StaggeredGridLayoutManager, then in Adapter override getItemViewType(int position) method to return different viewTypes based on your cell/data type so when you inflate the items in onCreateViewHolder(ViewGroup parent, final int viewType) you can chose a different layout for the cell based on viewType.
Post a Comment for "Gridview: Gridview With Different Cells Sizes And Layout,"