Staggered grid layout manager dynamic number of columns

后端 未结 1 1285
夕颜
夕颜 2020-12-28 21:52

How i can make dynamic number of columns in RecyclerView using StaggeredGridLayoutManager. I already have working RecyclerView. Here i

相关标签:
1条回答
  • 2020-12-28 22:31

    if max columns are two that would be quite simple.For the view that occupy the full width,setFullSpan(true) like in your BindView method of Recyclerview Adapter

    //rlm is RecyclerView.LayoutManager passed in constructor or setter in adapter 
    if (rlm instanceof StaggeredGridLayoutManager) {
       StaggeredGridLayoutManager.LayoutParams layoutParams = (StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams();
        /*
         * to make View to occupy full width of the parent
         */
         layoutParams.setFullSpan(true);
    }
    
    0 讨论(0)
提交回复
热议问题