我正在努力让表格单元格的内容左/右对齐。我的代码是:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow
android:id="@+id/tableRow4"
android:layout_weight="1" >
<ImageButton
android:id="@+id/button_one"
android:layout_height="fill_parent"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="@null"
android:scaleType="fitCenter"
android:src="@drawable/button_one" />
<ImageButton
android:id="@+id/button_two"
android:layout_height="fill_parent"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="@null"
android:scaleType="fitCenter"
android:src="@drawable/button_two" />
</TableRow>
....
我希望 2 个 ImageButton 在中间紧贴在一起,但目前有一个间隙 - 看起来每个单元格都将内容居中。表格扩展到屏幕的全尺寸,总共有 4 行,与上面相同。我希望图像按钮调整大小以填满屏幕,同时保持其纵横比。
我试过在图像按钮上设置重力,但它似乎不起作用(它只移动了几个像素)。
最佳答案
按钮上缺少 android:layout_width="0dp"
,这将允许布局权重起作用,使每个按钮平均分配可用空间。
关于Android对齐表格的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11282694/