0

我想要两个按钮,如下所示: [ 使用 ] [ 取消 ] (这些只是带有背景图像的按钮,而不是 ImageButtons)

但是结果很奇怪,第一个按钮填满了所有的空间,在线性布局中是这样的:[.............Use............] 而取消按钮是未显示。两个按钮的 layout_width 都是“wrap_content”,而线性布局的方向是水平的,有什么问题?

得到一个代码:

 <LinearLayout 
   android:layout_width="fill_parent"
   android:orientation="horizontal"
   android:id="@+id/linearLayout2" 
   android:layout_gravity="bottom" 
   android:layout_height="fill_parent" 
   android:layout_weight="1">


       <Button 
       android:text="Use" 
       android:height="14dp"
       android:textSize="15sp"
       android:textColor="#ffffff"
       android:background="@drawable/button1"
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/UseButtonDialog" 
       android:layout_gravity="bottom">
       </Button>


        <Button android:text="Cancel" 
        android:background="@drawable/button1"
        android:height="14dp"
        android:textSize="15sp"
        android:textColor="#ffffff"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:id="@+id/CancelButtonDialog" 
        android:layout_gravity="bottom">
        </Button>


   </LinearLayout>

我应该对图像做些什么?

4

2 回答 2

5

为两个按钮添加 layout_weight 属性。将其设置为 1。

或者也许从线性布局中删除 layout_weight 也可以。

于 2011-11-22T12:04:34.700 回答
3

用这个:

weight=1每个组件(或给weightsum=1&LinearLayout权重 0.5 到Buttons

<LinearLayout android:layout_width="fill_parent"
   android:orientation="horizontal"
   android:id="@+id/linearLayout2" 
   android:layout_gravity="bottom" 
   android:layout_height="fill_parent">
       <Button android:weight="1"
       android:text="Use" 
       android:height="14dp"
       android:textSize="15sp"
       android:textColor="#ffffff"
       android:background="@drawable/button1"
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/UseButtonDialog" 
       android:layout_gravity="bottom">
       </Button>
        <Button android:weight="1"
        android:text="Cancel" 
        android:background="@drawable/button1"
        android:height="14dp"
        android:textSize="15sp"
        android:textColor="#ffffff"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:id="@+id/CancelButtonDialog" 
        android:layout_gravity="bottom">
        </Button>
</LinearLayout>
于 2011-11-22T12:04:11.180 回答