使按钮在布局相同的宽度 [英] Make buttons have the same width in layout
本文介绍了使按钮在布局相同的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我把4个按钮的相对布局。 我希望他们有相同的宽度,并修正了手机的任何屏幕尺寸。 我的$ C $如下:C:
I put 4 buttons in a relative layout. I want them to have the same width, and fix for any screen size of a phone. My code as below:
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="38dp" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Button" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/button1"
android:text="Button" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/button2"
android:text="Button" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/button3"
android:text="Button" />
</RelativeLayout>
我应该怎么修改?
What should I modify?
推荐答案
切换到的LinearLayout,并给所有的按钮相同的权重。
Switch to a LinearLayout and give all the buttons equal weight.
例如:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="38dp"
android:orientation="horizontal">
<Button android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
<Button android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
<Button android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
</LinearLayout>
这篇关于使按钮在布局相同的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文