如何添加相邻两个Button? (背景图像按钮,不ImageButtons) [英] How to add two Buttons next to each other? (Buttons with background image, not ImageButtons)

查看:242
本文介绍了如何添加相邻两个Button? (背景图像按钮,不ImageButtons)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我接下来要对方这样的两个按钮:
[使用方法] [取消]
(这些都只是背景图片的按钮,而不是ImageButtons)

I want two buttons next to each other like this: [ Use ] [ Cancel ] (These are just buttons with background images, NOT ImageButtons)

但结果是奇怪的,第一个按钮填满所有的空间,在这样的线性布局:
[..........使用...........]和按钮没有示出的取消。
该layout_width是WRAP_CONTENT两个按钮,线性布局的方向是水平的什么问题?

But the result is strange, the first button fills all the space, in the linear layout like this: [..........Use...........] and the Cancel button is not shown. The layout_width are "wrap_content" for both buttons, and the linear layout's orientation is horizontal whats the problem?

得到了code:

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

是我应该做的图像?

Something should i do with the images?

推荐答案

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

add layout_weight attribute to both the buttons. set it to 1.

或者从线性布局去除layout_weight工作为好。

or maybe removing layout_weight from the linear layout works as well.

这篇关于如何添加相邻两个Button? (背景图像按钮,不ImageButtons)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆