Reputation: 47
I have 3 buttons in a layout. What I want to do is increase the size of the buttons so they fill the entire screen. How can I do that in the xml file?
Upvotes: 1
Views: 2056
Reputation: 1205
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button"
android:layout_weight="1"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button2"
android:layout_weight="1"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button3"
android:layout_weight="1"/>
</LinearLayout>
You need weightSum
Upvotes: 5
Reputation: 701
You need to put the buttons inside a LinearLayout and use weight:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="3">
<Button
android:layout_height="0dip"
android:layout_width="wrap_content"
android:layout_weight="1"
/>
<Button
android:layout_height="0dip"
android:layout_width="wrap_content"
android:layout_weight="1"
/>
<Button
android:layout_height="0dip"
android:layout_width="wrap_content"
android:layout_weight="1"
/>
Upvotes: 0
Reputation: 3045
You can use the weight
property of a LinearLayout
. I'm gonna make a guess and assume you want the buttons in a vertical layout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button_1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<Button
android:id="@+id/button_2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<Button
android:id="@+id/button_3"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
The Buttons
will always fill the screen and you can play with the weight value to modify their height
Upvotes: 1