2012-01-09 85 views
1

我想在XML中安排4个相同大小的电话宽度的按钮。我试图用它们的关系和按钮宽度作为“wrap_content”的相对布局来使用。但是我面临RelativeLayout的问题是循环关系是不允许的。如何安排电话宽度相同的按钮?

I need the icons to be placed like this in layout

回答

2

您可以使用android:layout_weight,使您的按钮等,并根据设备屏幕的宽度适合他们。您可以将android:layout_weight="1"应用于所有4个按钮。

+1

这是很好的解决方案@Lalit。 – Mihir 2012-03-02 13:25:09

1

使用LinearLayoutandroid:weightSum="1.0"并将android:layout_weight = "0.25"分配给您的每个4按钮(weight_sum/no of buttons)。

0

在相对布局你提到一个线性布局,其
的android:layout_width = “FILL_PARENT” 机器人:layout_weight_sum = “4”
的android:layout_width = “FILL_PARENT” 机器人:layout_weight = “1” 为所有按钮和他们的父母布局

它适合我。

0

我认为我的回答也会有所帮助,虽然这与上述问题没有直接关系。 我想在应用程序的页脚区域安排2个图标。这是我做的。

<LinearLayout 
    android:id="@+id/linearLayout2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" > 

    <ImageButton 
     android:id="@+id/back_arrow" 
     android:layout_width="0dip" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="16dp" 
     android:layout_weight=".5" 
     android:background="@android:color/transparent" 
     android:contentDescription="@string/Description" 
     android:onClick="onClickBtn" 
     android:layout_margin="35dp" 
     android:src="@drawable/backbut" /> 

    <ImageButton 
     android:id="@+id/imageButton2" 
     android:layout_width="0dip" 
     android:layout_height="wrap_content" 
     android:layout_weight=".5" 
     android:layout_margin="35dp" 
     android:background="@drawable/copy" 
     android:contentDescription="@string/Description" 
     android:onClick="onClickBtn" /> 
</LinearLayout> 

,因为我想给相同的宽度我已设置机器人:layout_weight =” 5" 和我想有amoung两个图标的余量。因此,我设置了android:layout_margin =“35dp”。