Android GridLayout:如何设置组件的大小?

时间:2013-10-27 01:54:44

标签: android android-layout

我刚发现Android有GridLayout,我写了这个小小的演示:

<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_gravity="center"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:columnCount="2"
    android:rowCount="2" >

    <Button
        android:id="@+id/button1"
        android:layout_row="0"
        android:layout_rowSpan="1"
        android:layout_column="0"
        android:layout_columnSpan="1"
        android:layout_gravity="fill"
        android:text="Button 1" />    

</GridLayout>

由于我将rowCountcolumnCount都设置为2,rowSpancolumnSpan都设置为1,我希望这样:

enter image description here

然而,这就是我实际得到的:

enter image description here

有谁知道我该如何解决这个问题?或者我以错误的方式使用GridLayout?谢谢!

1 个答案:

答案 0 :(得分:0)

Gridlayout不支持重量。在单元组中的组件周围放置等量的空间;使用CENTER对齐(或重力)。 您可以尝试以实际方式设置组件的宽度/长度。供参考,请看这个问题 How to make a GridLayout fit screen size