如何添加两个相邻的按钮?(带有背景图像的按钮,而不是 ImageButtons)

Ada*_*gyi 0 android android-button

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

但结果很奇怪,第一个按钮填满了所有空间,在线性布局中是这样的:[.........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>
Run Code Online (Sandbox Code Playgroud)

我应该对图像做些什么?

Sud*_*hat 5

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

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