草庐IT

gridlayoutmanager

全部标签

android - RecyclerView GridLayoutManager : how to auto-detect span count?

使用新的GridLayoutManager:https://developer.android.com/reference/android/support/v7/widget/GridLayoutManager.html它需要一个明确的跨度计数,所以现在问题变成了:你怎么知道每行有多少个“跨度”?毕竟,这是一个网格。根据测量的宽度,RecyclerView应该有尽可能多的跨度。使用旧的GridView,您只需设置“columnWidth”属性,它会自动检测有多少列适合。这基本上就是我想为RecyclerView复制的内容:在RecyclerView上添加OnLayoutChangeLi

Android Recyclerview GridLayoutManager 列间距

如何使用GridLayoutManager设置RecyclerView的列间距?在我的布局中设置边距/填充无效。 最佳答案 以下代码运行良好,每列宽度相同:publicclassGridSpacingItemDecorationextendsRecyclerView.ItemDecoration{privateintspanCount;privateintspacing;privatebooleanincludeEdge;publicGridSpacingItemDecoration(intspanCount,intspacing,