2014-04-10 54 views
0

我想在中间使用三个按钮进行布局。我打算再添加右侧角球2个按键,但现在我试图使其与这3个使所有按钮具有相同的尺寸

这项工作是我脑子里想的:

My idea

在某些方面,它应该在每个屏幕尺寸都相似(所以随着屏幕尺寸变小,按钮变小)。

现在,这是我所:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

<Button 
    android:id="@+id/multiplay" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true" 
    android:background="@drawable/menubutton" 
    android:text="@string/multiplayer" /> 

<Button 
    android:id="@+id/options" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/multiplay" 
    android:layout_below="@+id/multiplay" 
    android:background="@drawable/menubutton" 
    android:text="@string/options" /> 

<Button 
    android:id="@+id/singleplay" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/multiplay" 
    android:layout_alignLeft="@+id/multiplay" 
    android:background="@drawable/menubutton" 
    android:text="@string/singleplayer" 
/> 

看起来好像没什么大屏幕上,但在一个较小的这种情况:

On very small screen

我身边有一派,和大多数页面建议使用“重量”,但显然只适用于线性布局。有什么建议?

感谢

+0

什么是不使用线性布局的原因是什么? –

+0

为此使用线性更好吗? – Marshall

+0

考虑到你只是试图把3个按钮放在eachother之上,是的,最好使用LinearLayout。您仍然可以使用RelativeLayout作为整体布局(这样您可以稍后在右上角添加这些按钮),但在中间使用3个按钮的LinearLayout。 –

回答

1

试试这个..

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:orientation="vertical" > 

     <Button 
      android:id="@+id/multiplay" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/menubutton" 
      android:text="@string/multiplayer" /> 

     <Button 
      android:id="@+id/options" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/menubutton" 
      android:text="@string/options" /> 

     <Button 
      android:id="@+id/singleplay" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/menubutton" 
      android:text="@string/singleplayer" /> 
    </LinearLayout> 

</RelativeLayout> 
1

应使用重量,这样一来就可以均匀地devide屏幕上的按钮,无论什么屏幕尺寸。

这里是RelativeLayout中的LinearLayour示例。 (如果在RelativeLayout中没有其他的东西可以用LinearLayout替换RelativeLayout)

你应该玩一点它,以符合你的要求。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

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

<Button 
    android:id="@+id/multiplay" 
    android:layout_width="wrap_content" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:layout_centerHorizontal="true" 
    android:background="@drawable/menubutton" 
    android:text="@string/multiplayer" /> 

<Button 
    android:id="@+id/options" 
    android:layout_width="wrap_content" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:layout_centerHorizontal="true" 
    android:background="@drawable/menubutton" 
    android:text="@string/options" /> 

<Button 
    android:id="@+id/singleplay" 
    android:layout_width="wrap_content" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:layout_centerHorizontal="true" 
    android:background="@drawable/menubutton" 
    android:text="@string/singleplayer" 
/> 

    </LinearLayout> 

</RelativeLayout> 
相关问题