I have following three button in a Linear Layout with width fill_parent
.
How can I set the width of these buttons to equally cover the whole screen area?
<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"
/>
Consider making touch targets at least 48 x 48 dp, separated by 8 dp of space or more, to ensure balanced information density and usability. A touch target of 48 x 48 dp results in a physical size of about 9 mm, regardless of screen size.
Display display = getWindowManager(). getDefaultDisplay(); Point size = new Point(); display. getSize(size); int width = size. x; int height = size.
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. (Try playing around with different values of weight
for each button to see how that works)
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With