安卓:表格布局。在中间的行中对齐

标签 android android-tablelayout

请看 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>

enter image description here

在第二行的中间设置 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>

请看看发生了什么,这当然是不正确的: enter image description here

但是如何让行高相等还是不懂。

第二行现在的格式如下,但在 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/

相关文章:

java - 在 onRegistered 和 onUnregistered 方法中从 GCMIntentService 更新 TextView

android - TextViews 的某些部分不显示并被屏幕边缘截断

android - "android:layout_column"属性是什么?

java - 构造函数未定义错误 - Java

java - 如何协调两个后台任务?

Android:覆盖按钮的 onKeyListener 的问题

android - 无法在 native 调试版本上打开开发人员菜单

android - 表格行中的多行 TextView 未正确换行

java - ScrollView ,表格布局和线性布局在android中不能一起工作

android - 修复了第一个 TableRow android