简体   繁体   English

Android-设置RecyclerView GridLayoutManager列宽

[英]Android - setting RecyclerView GridLayoutManager columns width

I'm using a RecyclerView with GridLayoutManager , but as I have to specify how many columns I will be using, it divides all the columns width equally, and therefore, my RecyclerView messes up as on the picture below. 我正在将RecyclerViewGridLayoutManager ,但是由于必须指定要使用的列数,所以它会将所有列的宽度均分,因此,我的RecyclerView如下图所示。

。

As you can see, every item has a fixed width and not a wrap_content as I expected. 如您所见,每个项目都有固定的宽度,而不是我期望的wrap_content。

I assume you want each chip to have enough width to wrap its content, and you do not want every chip in a given column to have the same width. 我假设您希望每个筹码都具有足够的宽度来包装其内容,并且您不希望给定列中的每个筹码都具有相同的宽度。

If so, you probably do not want to use GridLayoutManager . 如果是这样,您可能不想使用GridLayoutManager Essentially no matter what you do, it will still wind up defining some fixed column width (though you can set it up so that different columns have different widths). 本质上,无论您做什么,它最终都会定义一些固定的列宽(尽管您可以进行设置以使不同的列具有不同的宽度)。 I believe a better choice would be FlexboxLayoutManager . 我相信更好的选择是FlexboxLayoutManager

FlexboxLayout is a library from Google that allows you to specify a set of items and have them lay themselves out, wrapping as necessary. FlexboxLayout是Google提供的一个库,可让您指定一组项目并让它们自行布置,并根据需要进行包装。 Find details here: https://github.com/google/flexbox-layout 在此处查找详细信息: https : //github.com/google/flexbox-layout

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM