我想要一个2x2的网格,里面有一个按钮.这只是ICS,所以我try 使用新的GridLayout.
以下是我的布局的XML:
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/favorites_grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00ff00"
android:rowCount="2"
android:columnCount="2">
<Button
android:text="Cell 0"
android:layout_row="0"
android:layout_column="0"
android:textSize="14dip" />
<Button
android:text="Cell 1"
android:layout_row="0"
android:layout_column="1"
android:textSize="14dip" />
<Button
android:text="Cell 2"
android:layout_row="1"
android:layout_column="0"
android:textSize="14dip" />
<Button
android:text="Cell 3"
android:layout_row="1"
android:layout_column="1"
android:textSize="14dip" />
</GridLayout>
问题是,我的视图在每一行中的拉伸并不均匀.这会在我的GridLayout右侧产生大量额外空间.
我try 设置layout_gravity="fill_horizontal"
,但这只适用于行上的last视图.这意味着单元格1会一直延伸,为单元格0提供足够的空间.
如何解决这个问题?