Pregunta

in my app i use relative layout for design.in an activity i have four buttons at bottom of the screen. my xml code(Land scape) does not suit for all device screen. it has more space between buttons as show in the figure. how to design the layout which is suit for all resolution screen (Landscape).

layout image is : enter image description here

my xml:

<RelativeLayout android:id="@+id/relativeLayout1"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:background="#0000FF"
xmlns:android="http://schemas.android.com/apk/res/android">


<RelativeLayout android:layout_width="fill_parent"
    android:layout_gravity="bottom" android:layout_alignParentBottom="true"
    android:background="@drawable/applicarion_bar" android:layout_height="wrap_content"
    android:id="@+id/relativeLayout4">

        <ImageButton android:id="@+id/homeimageButton2"
            android:layout_alignParentLeft="true"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:background="@drawable/festival_btn" />

        <ImageButton android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/homeimageButton2"
            android:layout_marginLeft="60dp"
            android:layout_width="wrap_content" android:background="@drawable/search_btn"
            android:id="@+id/homeimageButton3"></ImageButton>
        <TextView android:id="@+id/homecalendar4" android:text="MAR 20"
            android:layout_toRightOf="@+id/homeimageButton3"
            android:gravity="center"
            android:textSize="10dp"
            android:layout_marginLeft="60dp"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:background="@drawable/calendar_btn" />
        <ImageButton android:id="@+id/homeimageButton5"
            android:layout_alignParentRight="true"
            android:layout_marginLeft="10dp"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:background="@drawable/favorite_btn" />

</RelativeLayout>

¿Fue útil?

Solución

Replace your relativeLayout4 as

    <LinearLayout android:id="@+id/put_id_of_ll"
        android:orientation="horizontal" android:background="#012C58"
        android:paddingLeft="4.0dip" android:paddingTop="5.0dip"
        android:paddingRight="4.0dip" android:paddingBottom="1.0dip"
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:layout_alignParentBottom="true">
              <ImageButton android:id="@+id/homeimageButton2"
                android:layout_width="0.0dip"
                android:text="ImageButton"
                android:background="@drawable/festival_btn"
                android:layout_weight="1.0"
                android:layout_height="wrap_content"
                android:padding="10dp"
                android:layout_marginBottom="3dip"
                android:layout_marginLeft="2dip" />
            <ImageButton android:id="@+id/homeimageButton3"     
android:background="@drawable/search_btn"
                android:layout_width="0.0dip"
                android:text="btn2"
                android:layout_weight="1.0"
                android:layout_height="wrap_content"
                android:padding="10dp"
                android:layout_marginBottom="3dip"
                android:layout_marginLeft="2dip" />
            <TextView android:id="@+id/homecalendar4" android:text="MAR 20"
                android:layout_width="0.0dip"
                android:layout_weight="1.0"
                android:layout_height="wrap_content"
                android:padding="10dp"
                android:layout_marginBottom="3dip"
                android:layout_marginLeft="2dip" />
            <ImageButton android:id="@+id/homeimageButton5"
                android:layout_width="0.0dip"
                android:text="btn4"
                android:background="@drawable/favorite_btn"
                android:layout_weight="1.0"
                android:layout_height="wrap_content"
                android:padding="10dp"
                android:layout_marginBottom="3dip"
                android:layout_marginLeft="2dip" />
        </LinearLayout>

It will work.

Happy coding :)

Otros consejos

use linear layout instead of relative layout, use below code

<RelativeLayout android:id="@+id/relativeLayout1"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:background="#0000FF"
xmlns:android="http://schemas.android.com/apk/res/android">


<LinearLayout android:layout_width="fill_parent"
    android:layout_gravity="bottom" android:orientation="horizontal"
    android:background="@drawable/applicarion_bar" android:layout_height="wrap_content"
    android:id="@+id/relativeLayout4">

        <ImageButton android:id="@+id/homeimageButton2"
            android:layout_alignParentLeft="true"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/festival_btn" />

        <ImageButton android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/homeimageButton2"
            android:layout_weight="1"
            android:layout_marginLeft="60dp"
            android:layout_width="wrap_content" android:background="@drawable/search_btn"
            android:id="@+id/homeimageButton3"></ImageButton>

        <TextView android:id="@+id/homecalendar4" android:text="MAR 20"
            android:layout_toRightOf="@+id/homeimageButton3"
            android:gravity="center"
            android:textSize="10dp"
            android:layout_marginLeft="60dp"
            android:layout_weight="1"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:background="@drawable/calendar_btn" />

        <ImageButton android:id="@+id/homeimageButton5"
            android:layout_alignParentRight="true"
            android:layout_marginLeft="10dp"
            android:layout_weight="1"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:background="@drawable/favorite_btn" />

</LinearLayout>

</RelativeLayout>

try to use a linear layout and give equal weight to all the views.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top