【问题标题】:Same Size Buttons in Two LinearLayouts两个线性布局中相同大小的按钮
【发布时间】:2011-03-29 04:47:23
【问题描述】:

我的Android 应用程序中有两个LinearLayouts。一个(顶部)包含一个TextView 和一个Button,下面的一个包含两个buttons。我想知道是否有办法使上部LinearLayout 的右键与底部LinearLayout 的右侧按钮大小相同。

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

【问题讨论】:

    标签: android xml android-layout layout android-linearlayout


    【解决方案1】:

    嗯,有两种方法可以做到这一点......

    1) 如果您按原样使用线性布局,那么您必须修复 Left TextView 和 Left ButtonWIDTH 然后不能包装内容,只是给他们说 40 dip。之后将 Right Buttons Width 设置为 fill_parent 或为它们修复 WIDTH。

    2) 使用 TableLayout 并将它们中的每一个放在各自的列和行中,TableLayout 应该会为您处理。

    【讨论】:

    • 只是为了跟进这一点,我现在所做的是每个按钮的宽度为 0dp,layout_weight 为 1。效果很好,但感谢您的帮助,很抱歉迟到了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多