简体   繁体   English

如何设置android中的按钮宽度来覆盖屏幕宽度?

[英]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.

相关问题 Android:调整GIF大小以覆盖屏幕宽度 - Android: Resize GIF to cover screen width Android按钮未拉伸到屏幕宽度 - Android Buttons not stretching to width of the screen 如何在Android RelativeLayout中为3个按钮设置相同的宽度? - How to set the same width for 3 buttons in android RelativeLayout? 根据屏幕Android Studio在GridLayout中设置按钮的宽度和高度 - Set width & height of buttons in GridLayout depending on screen Android Studio 如何在Android中为不同的屏幕尺寸宽度设置textview宽度? - How to set textview width for different screen size width in Android? Android如何将视图的宽度设置为屏幕宽度的一定比例? - Android how to set the width of a view to a certain ratio of the width of the screen? 如何根据屏幕尺寸设置单选按钮的宽度? (机器人) - How can I set the width of radio buttons to change with regards to screen size? (android) 如果有2个按钮(其中1个具有特殊宽度),如何设置按钮的宽度以固定线性布局中的其余屏幕尺寸 - How to set a Button's width to fix the remaining screen size inside a Linear Layout if there are 2 Buttons (1 with spcified width) 如何将RelativeLayout的宽度设置为屏幕宽度? - How I set the width of RelativeLayout to screen width? Android:如何将垂直线性布局中的两个按钮设置为相同的宽度? - Android: how to set two buttons in vertical linear layout to same width?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM