android - 交错网格布局管理器动态列数

标签 android android-recyclerview

我如何使用 StaggeredGridLayoutManagerRecyclerView 中创建动态列数。我已经有了工作 RecyclerView。这是我需要做的屏幕:

enter image description here

最佳答案

如果 max columns 是两个,那将非常简单。对于占据整个宽度的 View ,setFullSpan(true) 就像在 Recyclerview Adapter 的 BindView 方法中一样

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

关于android - 交错网格布局管理器动态列数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36218787/

相关文章:

android - 如何保存 RecyclerView 行项目的状态?

java - recyclerview onclicklistener java.lang.IndexOutOfBoundsException : Invalid index 0, 大小为0

android - 如何在android中同步滚动两个Recyclerviews?

java - 如何在Android 7.0版本的通话界面上方显示弹窗

android - 在 Android 中,从 SQLite 表中的特定范围抓取两个随机行

android - 解析本地xml android

Android - 在 DialogFragment 中设置 imageView

android - AppCompatRadioButton 的 RadioGroup 不适用于 Jelly Bean?

java - API < 21 的 Android 复选框按钮样式

java - 用动态创造突破性的新标题