问题描述
我如何设置一个固定的宽度为Android的按钮?每次我尝试设置一个固定的宽度它填补了当前父(该RelativeView)。这里是我的XML:
How can I set a fixed width for an Android button? Everytime I try to set a fixed width it fills the current parent (the RelativeView). Here is my XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/relativelayout" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">
<EditText android:layout_height="wrap_content" android:editable="false" android:layout_width="fill_parent" android:id="@+id/output"></EditText>
<Button android:layout_height="wrap_content" android:id="@+id/Button01" android:layout_below="@id/output" android:text="7" android:layout_width="wrap_content"></Button>
<Button android:layout_below="@id/output" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/Button02" android:layout_toRightOf="@+id/Button01" android:text="8"></Button>
<Button android:layout_below="@id/output" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/Button03" android:layout_toRightOf="@+id/Button02" android:text="9"></Button>
</RelativeLayout>
我将如何给它一个固定的宽度?
更新
说我有我想要的尺寸相同,彼此的整个视图(纵向)1/3几个按钮,然后我要带双宽的按钮。然后用双高度的按钮。我怎么能做到这一点其他的手工上浆他们?
How would I give it a FIXED width?
UPDATE
Say I have several buttons that I want the same size as each other and 1/3 of the entire view (Portrait), then I want a button with double the width. Then a button with double the height. How could I accomplish this other that manually sizing them?
推荐答案
要完成你想要的,你可以使用的LinearLayout与weightsum。例如,你可以把9. WeightSum如果你把三个按钮的权重里面各1个。他们将采取地方的1/3,你可以把2的另一个对象。这个对象将是两倍大,其他的。
To accomplish what you want, you can use a LinearLayout with a weightsum. For example, you can put a WeightSum of 9. If you put the weight of three button inside to 1 each. They will take 1/3 of the place, and you can put 2 for another object. This object will be twice as big as the other.
http://developer.android.com/reference/android/widget/LinearLayout.html#setWeightSum(float)
编辑:我想补充的是,这才能正常工作,你必须设置宽度或高度为0px(取决于如果它是一个水平或垂直布局上)
I would like to add that for this to work correctly, you have to set the width or height to 0px (depending on if it's an horizontal or a vertical layout).
这篇关于巴顿在Android中设置宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!