I am developing an android app that will have a screen similar to the following image -
Please notice the banner ad between the cells. As GridView does not support such spanning of columns I am at a loss as to what to do.
Please provide any suggestions you can. Thanks in advance.
On my opinion, the best way to do it is to use RecyclerView with GridLayoutManager. Simply provide SpanSizeLookup for GridLayoutManager that can determine size of each position. For example, first position need to ocupate full row
//Two items in a row
int spanCount = 2;
GridLayoutManager manager = new GridLayoutManager(getActivity(),spanCount);
manager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
return (position == 0 ? spanCount : 1);
}
});
In your adapter provide 2 types of items - usual item and advertisement item
It is preferable to set item paddings via ItemDecoration.
I can provide more code if needed
You need to create two layouts for items in Gridview Adapter. One for what you want to show and other for adView and alternately place layout while creating view.
Check this to get more idea.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With