填补空白,布局问题

时间:2014-11-17 14:12:50

标签: android android-layout

我正在创建一个simon说应用程序,除了布局之外它还顺利。 正如你在下面的图片中看到的,我不知道如何让我的按钮像右边的例子一样。

我尝试了很多东西,但没有一个能够奏效,我只是想按钮会自动填满他们所拥有的空间。

我的XML文件如下所示(左侧示例):

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.xyz.MainActivity" >

    <RelativeLayout
        android:id="@+id/row_one"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/score"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/gameScore" />

        <TextView
            android:id="@+id/turn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:text="Who&apos;s turn is it?" />
    </RelativeLayout>

    <LinearLayout
        android:id="@+id/row_two"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/row_one" >

        <Button
            android:id="@+id/green"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginRight="3dp"
            android:layout_weight="1"
            android:background="@drawable/green_button"
            android:onClick="simon_onClick"
            android:padding="3dp"
            android:text="Green"
            android:textColor="#ffffff" />

        <Button
            android:id="@+id/red"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="1"
            android:background="@drawable/red_button"
            android:onClick="simon_onClick"
            android:padding="3dp"
            android:text="Red"
            android:textColor="#ffffff" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/row_three"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/row_two"
        android:layout_marginTop="2dp" >

        <Button
            android:id="@+id/yellow"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginRight="3dp"
            android:layout_weight="1"
            android:background="@drawable/yellow_button"
            android:onClick="simon_onClick"
            android:padding="3dp"
            android:text="Yellow"
            android:textColor="#ffffff" />

        <Button
            android:id="@+id/blue"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="1"
            android:background="@drawable/blue_button"
            android:onClick="simon_onClick"
            android:padding="3dp"
            android:text="Blue"
            android:textColor="#ffffff" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dip"
            android:layout_weight="1"
            android:gravity="center|bottom"
            android:orientation="vertical" >

            <Button
                android:id="@+id/status"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal|center"
                android:onClick="startGame"
                android:text="@string/gameStatus_start" />
        </LinearLayout>
    </LinearLayout>
</RelativeLayout>

Simon says

提前谢谢你们!

2 个答案:

答案 0 :(得分:0)

您可以使用LinearLayout(Vertical)作为根布局吗?

答案 1 :(得分:0)

你也可以使用这个:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:orientation="vertical"
android:paddingTop="10dp" >

<LinearLayout
    android:id="@+id/row_one"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="30dp" >

    <TextView
        android:id="@+id/score"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="gameScore" />

    <TextView
        android:id="@+id/turn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:text="Who&apos;s turn is it?" />
</LinearLayout>

<LinearLayout
    android:id="@+id/row_two"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="2" >

    <Button
        android:id="@+id/green"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_gravity="center_vertical"
        android:layout_marginRight="3dp"
        android:layout_weight="1"
        android:background="#00ff00"
        android:onClick="simon_onClick"
        android:padding="3dp"
        android:text="Green"
        android:textColor="#ffffff" />

    <Button
        android:id="@+id/red"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_gravity="center_vertical"
        android:layout_weight="1"
        android:background="#ff0000"
        android:onClick="simon_onClick"
        android:padding="3dp"
        android:text="Red"
        android:textColor="#ffffff" />
</LinearLayout>

<LinearLayout
    android:id="@+id/row_three"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="2"
    android:layout_marginTop="2dp" >

    <Button
        android:id="@+id/yellow"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_gravity="center_vertical"
        android:layout_marginRight="3dp"
        android:layout_weight="1"
        android:background="#ddaa00"
        android:onClick="simon_onClick"
        android:padding="3dp"
        android:text="Yellow"
        android:textColor="#ffffff" />

    <Button
        android:id="@+id/blue"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_gravity="center_vertical"
        android:layout_weight="1"
        android:background="#0000ff"
        android:onClick="simon_onClick"
        android:padding="3dp"
        android:text="Blue"
        android:textColor="#ffffff" />
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="40dp"
    android:orientation="vertical"
    android:layout_gravity="bottom"
     >
        <Button
            android:id="@+id/status"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal|center"
            android:onClick="startGame"
            android:text="gameStatus_start" />
</LinearLayout>

相关问题