你如何在GridView中均匀分配孩子?

时间:2022-07-13 21:33:24

This question is related to my other post about getting the parent view of a child in a GridView, the setup has not changed dramatically. This GridView belongs in a fragment.

这个问题与我关于在GridView中获取子视图的父视图的其他帖子有关,设置没有发生显着变化。这个GridView属于一个片段。

As in my other post, the layout is as follows:

在我的另一篇文章中,布局如下:

  • GridView - Inflates the following with an adapter...
    • LinearLayout
      • TextView
  • GridView - 使用适配器对以下内容进行充气... LinearLayout TextView

I am trying to get the children of this view to fill all the available space on the display. The scaling of the text at this point is unimportant.

我试图让这个视图的孩子们填满显示器上的所有可用空间。此时文本的缩放并不重要。

The elements are normally arranged in a square grid, the count of which is supplied by myObject.GridSize

元素通常排列在方形网格中,其计数由myObject.GridSize提供

I have so far only tried changing the attributes in XML, with a failed attempt to modify the children's width/height after the adapter has filled it, the code of which is just ignored. I've also tried a test layout to get a small 6x6 grid of buttons to stretch evenly across the view using weights on the parent layouts, which is proving impossible.

到目前为止,我只尝试更改XML中的属性,尝试在适配器填充后修改子节点的宽度/高度失败,其代码被忽略。我还尝试了一个测试布局来获得一个小的6x6网格按钮,使用父布局上的权重在视图中均匀拉伸,这是不可能的。

Researching this issue has led me down to all kinds of unusual problems android:stretchMode="spacingWidthUniform" made the views not generate, so I'm asking if any of you have seen this problem, and know the solution.

研究这个问题导致我遇到各种不寻常的问题android:stretchMode =“spacingWidthUniform”使视图无法生成,所以我问你们是否有人看过这个问题,并且知道解决方案。

1 个解决方案

#1


0  

As there is no clear solution within the android framework for this functionality (without hacking it to bits) for now I've had to succumb to defining individual layouts depending on the devices size (something of which I cannot stand).

因为在这个功能的android框架中没有明确的解决方案(没有乱砍它)现在我不得不屈服于根据设备大小定义单独的布局(我不能忍受的东西)。

Unless anyone (or if google) have a solution, please post anyway, and if it works, you'll be marked as the answer.

除非任何人(或谷歌)有解决方案,否则请发布,如果有效,您将被标记为答案。

Thanks.

#1


0  

As there is no clear solution within the android framework for this functionality (without hacking it to bits) for now I've had to succumb to defining individual layouts depending on the devices size (something of which I cannot stand).

因为在这个功能的android框架中没有明确的解决方案(没有乱砍它)现在我不得不屈服于根据设备大小定义单独的布局(我不能忍受的东西)。

Unless anyone (or if google) have a solution, please post anyway, and if it works, you'll be marked as the answer.

除非任何人(或谷歌)有解决方案,否则请发布,如果有效,您将被标记为答案。

Thanks.