2011-03-29 44 views
2

我在我的Android應用程序中有兩個LinearLayout s。一個(頂部)持有TextViewButton,下面的持有兩個button。我想知道是否有辦法讓上部LinearLayout的右側按鈕與底部LinearLayout的右側按鈕的大小相同。兩個LinearLayouts中的相同大小按鈕

<LinearLayout android:layout_width="fill_parent" 
    android:id="@+id/linearLayout1" android:layout_height="wrap_content" 
    android:orientation="horizontal" android:paddingTop="15.0dip"> 

    <TextView 
      android:paddingLeft="5.0dip" 
      android:textSize="33px" 
      android:textStyle="bold" 
      android:layout_height="wrap_content" 
      android:id="@+id/textViewPoints" 
      android:text="Points: 0" 
      android:layout_width="wrap_content" 
      android:layout_gravity="center_vertical" 
      android:paddingRight="25.0dip" 
      android:layout_weight="0" /> 

    <Button 
      android:enabled="false" 
      android:onClick="myClickHandler" 
      android:layout_height="wrap_content" 
      android:id="@+id/buttonAddTracker" 
      android:layout_width="fill_parent" 
      android:layout_gravity="center_vertical" 
      android:text="@string/buttonAddTracker" 
      android:layout_weight="1" /> 
</LinearLayout> 

<LinearLayout 
    android:orientation="horizontal" 
    android:id="@+id/linearLayout2" android:layout_width="fill_parent" 
    android:layout_height="wrap_content" android:paddingTop="15.0dip"> 

    <Button 
      android:text="Calculate" 
      android:id="@+id/button01" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:onClick="myClickHandler" /> 

    <Button 
      android:text="Reset" 
      android:id="@+id/button02" 
      android:layout_toRightOf="@+id/button01" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:onClick="myClickHandler"></Button> 
</LinearLayout> 

回答

2

那麼有兩種方法可以怎麼做...

1)如果您正在使用線性佈局,你是,那麼你就必須修復WIDTH左邊的TextView和左邊的按鈕然後不能包裝內容,只是給他們說40傾角。之後,把正確的按鈕寬度fill_parent或修復他們的WIDTH。

2)使用TableLayout並把它們放在它們各自的列和行中,TableLayout應該爲你處理它。

+0

+1 for TableLayout – 2011-03-29 05:38:58

+0

爲了跟上這一點,我現在所做的是每個按鈕的0dp和layout_weight的WIDTH爲1。完美的工作,但感謝您的幫助,併爲遲到的接受感到抱歉。 – mattdonders 2012-07-19 17:13:35

相關問題