请看 XML
<TableLayout
android:layout_weight="0"
android:background="@color/black"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_marginStart="0dp"
android:layout_marginTop="0dp">
<TableRow android:orientation="horizontal" android:layout_weight="1" android:layout_height="wrap_content"></TableRow>
<TableRow
android:layout_gravity="center"
android:orientation="horizontal"
android:layout_weight="1"
android:layout_height="wrap_content">
<ImageButton
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/tmp0"
android:id="@+id/startButton">
</ImageButton></TableRow>
<TableRow android:layout_weight="1" android:layout_height="wrap_content" android:weightSum="3"></TableRow>
</TableLayout>
在第二行的中间设置 ImageButton 时遗漏或错误设置了哪些属性? (垂直和水平)
如何使行高和宽度相等?
我在问题/答案库中搜索没有成功..
==========================
更新:
要将 Button 放在中间,第二行应标记如下:
<TableRow **android:gravity="center"** android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:weightSum="3"> <ImageButton android:layout_gravity="center" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/tmp0" android:id="@+id/startButton"> </ImageButton> </TableRow>
但是如何让行高相等还是不懂。
第二行现在的格式如下,但在 Designer 中它与第二张图片相同
<TableRow
android:gravity="center"
android:layout_gravity="center"
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:weightSum="3">
<ImageButton
android:layout_gravity="center"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/tmp0"
android:id="@+id/startButton">
</ImageButton>
</TableRow>
最佳答案
如果我没记错的话,第二行需要 android:layout_width="match_parent"
关于安卓:表格布局。在中间的行中对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45894686/