我希望有一个带有按钮的2x2网格.这只是ICS所以我试图使用给定的新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>
Run Code Online (Sandbox Code Playgroud)
问题是我的视图不能均匀地拉伸到每一行.这会在GridLayout的右侧产生大量额外空间.
我试过设置,layout_gravity="fill_horizontal"
但只适用于行的最后一个视图.这意味着Cell 1一直延伸为Cell 0提供足够的空间.
关于如何解决这个问题的想法?