如何使GridLayoutManager使用动态空间?

时间:2019-04-11 10:18:10

标签: android android-layout android-gridlayout gridlayoutmanager

我目前正在为RecyclerView使用GridLayoutManager,它显示不同文章的预览,这些文章的文本长度不同,因此项目高度也不同。问题是,我该如何使用整个高度而没有太多的间距?

enter image description here

3 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

尝试为Recyclerview设置像这样的布局管理器。

Enter the total items: 3
Enter the shopping item: shopping_item_1
Enter the price of item: 1
Enter the shopping item: shopping_item_2
Enter the price of item: 2
Enter the shopping item: shopping_item_3
Enter the price of item: 3

The Total of shopping_item_1, shopping_item_2, shopping_item_3 is 6 and the average price of the items are 1.0

SpacesItemDecorationNew

adapter = new CustomAdapter(R.layout.layout, list, context);
final StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(numberOfrows, StaggeredGridLayoutManager.HORIZONTAL);
recyclerView_sk.setHasFixedSize(true);
recyclerView_sk.addItemDecoration(new SpacesItemDecorationNew(0));//For equal distribution of columns.
recyclerView_sk.setLayoutManager(layoutManager);
recyclerView_sk.setAdapter(adapter);

答案 2 :(得分:0)

此外,您可以尝试

> f :: (Bar a1 b, Foo a2 a1) => a2 -> b
> f x = bar (foo x)