网格布局列宽 [英] GridLayout Column width

查看:154
本文介绍了网格布局列宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网​​格布局 2列。我想要做的就是让那些列占据半个屏幕宽度的每一个,然后让其子的内容填充自己的细胞宽度/高度。我试着设置孩子 FILL_PARENT 但这只是导致第一个接管整个布局。它似乎网格布局不支持重量?也许有一个更好的布局使用,但我希望有一个网格式的布局,这样似乎是一个自然的选择。

I have 2 columns in my GridLayout. What I want to do is make those columns take up half of the width of the screen each and then have its child contents fill their own cells width/height. I tried setting the children to fill_parent but that just causes the first one to take over the entire layout. And it seems GridLayout doesn't support weight? Maybe there is a better layout to use, but I want a Grid style layout so that seems like the natural choice.

推荐答案

###编辑###

这code是唯一可用的,因为API21!

This code is only available since API21 !

##########

我有一段简单的code显示4个按钮中的2列需要的可用空间的50%的网格布局: 也许它可以帮助

I have a simple piece of code to show 4 buttons in a gridLayout of 2 columns that take 50% of the available space: perhaps it can help

<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>

解决方案也许是这样的:

Solution is perhaps this :

    android:layout_gravity="fill"
    android:layout_columnWeight="1"

这篇关于网格布局列宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆