Reputation: 7129
I need to resize 3 buttons in order to fit every screen size so I tried to use a vertical Linear Layout but the result is the following:
This is the result I get on the ldpi/mdpi devices, but when I switch to higher resolutions like hdpi I get this:
the third button gets zoomed.
How can I resize the 3 buttons in order to fit the screen?
Upvotes: 1
Views: 2566
Reputation: 6515
try this :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="3" >
<Button
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="b1" />
<Button
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="b2" />
<Button
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="b3" />
</LinearLayout>
Upvotes: 2
Reputation: 5595
Try this:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="#5E616B"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:weightSum="1" >
<ImageButton
android:id="@+id/btn_pingsheet"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="15dp"
android:layout_marginTop="2dp"
android:layout_weight=".2"
android:background="@drawable/footer_button_pressed"
android:src="@drawable/pingicon" />
<ImageButton
android:id="@+id/btn_myprofile"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="15dp"
android:layout_marginTop="2dp"
android:layout_weight=".2"
android:background="@drawable/footer_button_pressed"
android:src="@drawable/profile" />
<ImageButton
android:id="@+id/btn_mycircle"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="15dp"
android:layout_marginTop="2dp"
android:layout_weight=".2"
android:background="@drawable/footer_button_pressed"
android:src="@drawable/mycircle" />
<ImageButton
android:id="@+id/btn_sendping"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="15dp"
android:layout_marginTop="2dp"
android:layout_weight=".2"
android:background="@drawable/footer_button_pressed"
android:src="@drawable/sendping" />
<ImageButton
android:id="@+id/btn_settings"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="15dp"
android:layout_marginTop="2dp"
android:layout_weight=".2"
android:background="@drawable/footer_button_pressed"
android:src="@drawable/settings" />
</LinearLayout>
The basic concept here is to take a linear layout with weightsum 1.Then divide that weight into each of the buttons(I have taken 5 buttons so divided it as .2 for each). You can divide the weight with android:layout_weight=".2"
attribute.Also dont forget to set the orientation of the linear layout to horizontal.
Upvotes: 3
Reputation: 1343
place the buttons in a linearlayout (horizontal)
add android:weightSum="3"
to the linear layout
add android:layout_weight="1"
for each of the buttons
and make their layout_width="0dp"
This will resize the buttons
(width) responsively on the size of the device.
Upvotes: 3