交错的网格布局管理器动态列数 [英] Staggered grid layout manager dynamic number of columns

查看:71
本文介绍了交错的网格布局管理器动态列数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用StaggeredGridLayoutManager使RecyclerView中的动态列数.我已经在工作RecyclerView.这是我需要做的屏幕:

How i can make dynamic number of columns in RecyclerView using StaggeredGridLayoutManager. I already have working RecyclerView. Here is screen what i need to do:

推荐答案

如果max列是两个,那将非常简单.对于占据全宽的视图,请像在Recyclerview Adapter的BindView方法中那样使用setFullSpan(true)

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);
}

这篇关于交错的网格布局管理器动态列数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆