2013-02-21 62 views
1

我一直在尋找最好的方式做這樣一個佈局:做一個佈局,四個按鈕可調整大小

enter image description here

底部的四個按鈕應該佔據儘可能大的空間,但每次都要與其他人具有相同的尺寸。 我試着用TableLayout和一些LinearLayout拼接在一起,但我無法得到我想要的結果。

+0

有什麼問題你有沒有在你的代碼面對? – 2013-02-21 12:49:02

+0

你能提供我們你的代碼嗎? – itsrajesh4uguys 2013-02-21 12:53:17

回答

2

代碼:

<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" > 

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

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:orientation="vertical" > 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:orientation="horizontal" > 

     <Button 
      android:id="@+id/button1" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:text="Button" /> 

     <Button 
      android:id="@+id/button2" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:text="Button" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:orientation="horizontal" > 

     <Button 
      android:id="@+id/button3" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:text="Button" /> 

     <Button 
      android:id="@+id/button4" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:text="Button" /> 
    </LinearLayout> 
</LinearLayout> 

enter image description here

+0

您節省了我的一天:) – hyperloris 2013-02-21 13:09:03

+0

@HyperLoris代碼有效,但您應該避免嵌套權重,因爲您可以通過更好的性能實現該佈局。 – Luksprog 2013-02-21 13:14:06