0

我正在为安卓游戏设计一个 GUI。到目前为止,我设计了这个

在此处输入图像描述

这是我的代码

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="bottom"
    android:orientation="vertical"
    tools:context=".Start"
    tools:ignore="MergeRootFrame" >

    <GridLayout
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:columnCount="1"
        android:padding="10dip"
        android:rowCount="3" >

        <Button
            android:id="@+id/nG"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dip"
            android:layout_marginTop="40dip"
            android:background="@drawable/red"
            android:onClick="nGame"
            android:text="New" />

        <Button
            android:id="@+id/hS"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dip"
            android:layout_marginTop="20dip"
            android:background="@drawable/green"
            android:onClick="hScore"
            android:text="High Scores" />

        <Button
            android:id="@+id/a"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dip"
            android:layout_marginTop="20dip"
            android:background="@drawable/blue"
            android:onClick="about"
            android:text="About" />

    </GridLayout>

</LinearLayout>

但我想这样看我的用户界面

在此处输入图像描述

我尝试使用 android:gravity 来做到这一点。但我无法找到解决方案。

4

2 回答 2

0

您可以使用RelativeLayout来实现这一点。您也可以先在您的 xml 文件(第一个孩子)中添加一个空视图。像这样:

<View android:layout_height="0dp"
android:layout_width="0dp"
android:layout_weight="1"
/>

空白空间往往会占用所有可用空间。因此,保留按钮后剩余的空间将被此视图占用。

于 2014-07-24T16:16:20.477 回答
0

不要使用 layout_gravity。只需使用

android:gravity="bottom"

于 2014-07-24T16:24:57.120 回答