How to show banner ads intermittently in gridview

后端 未结 4 882
后悔当初
后悔当初 2021-02-14 14:17

I am developing an android app that will have a screen similar to the following image - \"enter

4条回答
  •  不知归路
    2021-02-14 14:40

    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

提交回复
热议问题