[英]how to set width of buttons in android to cover screen width?
friends, 朋友们,
i have following three button in linear layout with width fill_parent 我有三个线性布局按钮,宽度为fill_parent
now how can i set width of these buttons to cover whole screen area equally? 现在我如何设置这些按钮的宽度以平均覆盖整个屏幕区域?
any help would be appriciated. 任何帮助都会得到满足。
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnReplyMessage"
android:gravity="left"
android:text="Reply"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnMarkAsUnread"
android:gravity="left"
android:text="Mark as unread"
/>
<ImageButton
android:id="@+id/btnDeleteMessage"
android:src="@drawable/imgsearch"
android:gravity="right"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
/>
Give all buttons the following properties 为所有按钮提供以下属性
android:layout_width="fill_parent"
android:layout_weight="1"
fill_parent
tells them to consume as much width as possible, and weight
determines how that width shall be distributed, when more than one control are competing for the same space. fill_parent
告诉他们消耗尽可能宽的宽度,并且当多个控件竞争相同的空间时, weight
确定如何分配该宽度。 (Try playing around with different values of weight
for each button to see how that works) (尝试使用每个按钮的不同
weight
值来查看其工作原理)
You should just specify these attributes for each button: 您应该为每个按钮指定以下属性:
android:layout_width="fill_parent"
android:layout_weight="1"
So it should be something like that: 所以它应该是这样的:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
you can use following code: 你可以使用以下代码:
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
You must to do 0dp in width on every button. 你必须在每个按钮上做0dp的宽度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.