GridLayout 列宽

2024-04-03

我的目录中有 2 列GridLayout。我想要做的是让这些列各自占据屏幕宽度的一半,然后让它的子内容填充它们自己的单元格宽度/高度。我尝试让孩子们fill_parent但这只会导致第一个占据整个布局。而且 GridLayout 似乎不支持weight?也许有更好的布局可供使用,但我想要网格样式布局,因此这似乎是自然的选择。


此代码可在 API21 之前的版本中通过支持库获得!

我有一段简单的代码,用于在 2 列的 gridLayout 中显示 4 个按钮,占用 50% 的可用空间: 也许它可以帮助

<GridLayout
    android:id="@+id/grid"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:columnCount="2"
    >


    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"
        android:layout_gravity="fill"
        android:layout_columnWeight="1"
        />

       <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"
        android:layout_gravity="fill"
        android:layout_columnWeight="1"
        />

       <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"
        android:layout_gravity="fill"
        android:layout_columnWeight="1"
        />

       <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"
        android:layout_gravity="fill"
        android:layout_columnWeight="1"
        />



</GridLayout>

解决方案也许是这样的:

android:layout_gravity="fill"
android:layout_columnWeight="1"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

GridLayout 列宽 的相关文章

随机推荐