繁体   English   中英

Android的XML布局未在中心完美对齐

[英]XML layout android not aligned perfectly in the center

这是我的xml布局代码

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView android:id="@+id/titleset"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Orb Runner"
    android:layout_gravity="center"
    android:gravity="center"
    android:layout_marginTop="20dp"
    android:textSize="45sp"
    android:textColor="#FF3366CC"/>

    <TableLayout android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:layout_marginTop="30dp"
    android:gravity="center"
    android:layout_gravity="center">

    <TableRow android:layout_gravity="center"
    android:gravity="center" android:layout_width="fill_parent">

    <TextView android:id="@+id/newgamebut"
    android:layout_marginRight="5dp"
    android:text="New Game"
    style="@style/Button" android:layout_height="fill_parent" android:layout_width="wrap_content"/>

    <TextView android:id="@+id/newgamebut"
    android:layout_marginLeft="5dp"
    android:text="High Score"
    android:layout_gravity="center"
    style="@style/Button" android:layout_height="fill_parent" android:layout_width="fill_parent"/>

    </TableRow>

    <TableRow android:layout_gravity="center"
    android:gravity="center" android:layout_width="fill_parent">

    <TextView android:id="@+id/newgamebut"
    android:layout_marginRight="5dp"
    android:text="Settings"
    style="@style/Button" android:layout_height="fill_parent" android:layout_width="wrap_content"/>

    <TextView android:id="@+id/newgamebut"
    android:layout_marginLeft="5dp"
    android:text="Instructions"
    android:layout_gravity="center"
    style="@style/Button" android:layout_height="fill_parent" android:layout_width="fill_parent"/>

    </TableRow>

    <TableRow android:layout_gravity="center"
    android:gravity="center" android:layout_width="fill_parent">

    <TextView android:id="@+id/newgamebut"
    android:layout_marginRight="5dp"
    android:text="About"
    style="@style/Button" android:layout_height="fill_parent" android:layout_width="wrap_content"/>

    <TextView android:id="@+id/newgamebut"
    android:layout_marginLeft="5dp"
    android:text="Exit Game"
    android:layout_gravity="center"
    style="@style/Button" android:layout_height="fill_parent" android:layout_width="fill_parent"/>

    </TableRow>

    </TableLayout>
</LinearLayout>

我想做的是使指令textview / button完全与当前顶部的行对齐,这就是它的样子。

| New Game |   | High Scores |
| Settings |  | Instructions |
|   About  |   |  Exit Game  |

我希望它看起来像这样

| New Game |   | High Scores |
| Settings |   | Instructions|
|  About   |   |  Exit Game  |

您可以使用android:weightSumandroid:layout_weight属性为textview / button分配相对宽度。

听起来可能很奇怪,但在使用layout_weight时,我也建议您将android:layout_width="0dp"用于您的按钮和android:layout_width="0dp"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM