2014-11-17 46 views
0

我正在创建一个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

预先感谢您的家伙!

回答

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> 

0

你可以使用LinearLayout(垂直)作为根布局吗?