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

UMA*_*MAR 16 layout android

朋友们,

我有三个线性布局按钮,宽度为fill_parent

现在我如何设置这些按钮的宽度以平均覆盖整个屏幕区域?

任何帮助都会得到满足.

<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"
 />
Run Code Online (Sandbox Code Playgroud)

Dav*_*und 35

为所有按钮提供以下属性

android:layout_width="fill_parent"
android:layout_weight="1"
Run Code Online (Sandbox Code Playgroud)

fill_parent告诉他们消耗尽可能宽的宽度,并weight确定当多个控件竞争同一空间时该宽度应如何分布.(尝试使用weight每个按钮的不同值来查看其工作原理)


Fed*_*dor 7

您应该为每个按钮指定以下属性:

android:layout_width="fill_parent"
android:layout_weight="1"
Run Code Online (Sandbox Code Playgroud)

所以它应该是这样的:

<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>
Run Code Online (Sandbox Code Playgroud)