0

I am trying to learn the android platform and everything was perfectly fine. I made a mistake and never switched to other phone to check my layout. So, I did it today and the result was disappointed. I am using RelativeLayout but mostly with height and fill_parent in width.

Here is my one of the layout file:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffd5d6d6">

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="47dip"
    android:background="#ffffffff">

    <ImageView
        android:id="@+id/flag"
        android:layout_width="24dp"
        android:layout_height="24dp"
        android:src="@drawable/ic_back"
        android:layout_centerVertical="true"
        android:layout_marginLeft="16dp" />

    <TextView
        android:id="@+id/profileDesc"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Roommate"
        android:textColor="#ff3c3f41"
        android:textSize="19dp"
        android:layout_centerInParent="true" />
</RelativeLayout>

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginTop="52dp">

    <TextView
        android:id="@+id/roommate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Who do you want your..."
        android:textColor="#ff3c3f41"
        android:textSize="20dp"
        android:layout_alignParentStart="false"
        android:layout_marginLeft="72dp"
        android:layout_marginRight="72dp"
        android:layout_marginTop="38dp" />

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginTop="84dp"
        android:layout_alignBottom="@+id/relativeLayout10">

        <TextView
            android:id="@+id/gender"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Gender"
            android:textColor="#ff3c3f41"
            android:textSize="19dp"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="38dp" />

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="89dp"
            android:layout_marginTop="81dp"
            android:layout_marginLeft="40dp"
            android:layout_marginRight="40dp"
            android:background="#ffffffff">
        </RelativeLayout>

        <TextView
            android:id="@+id/age"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Age"
            android:textColor="#ff3c3f41"
            android:textSize="19dp"
            android:layout_marginTop="215dp"
            android:layout_centerHorizontal="true" />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="150dp"
            android:layout_marginTop="258dp"
            android:layout_marginLeft="40dp"
            android:layout_marginRight="40dp"
            android:background="#ffffffff"
            android:id="@+id/relativeLayout6">

        </RelativeLayout>
    </RelativeLayout>

    <Button
        android:id="@+id/button"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="match_parent"
        android:layout_height="47dp"
        android:background="#fa6425"
        android:text="Next"
        android:textColor="#fff4f4f4"
        android:layout_alignParentBottom="true"
        android:layout_alignParentStart="true" />

</RelativeLayout>

Above layout is showing different alignment in different different phone screen. What would be the best way to fix this thing? Any help or guidance will be appreciable.

Edit-1

Community
  • 1
  • 1
Amit Pal
  • 10,604
  • 26
  • 80
  • 160

2 Answers2

0

You are using dp to position fixedly the elements relative to each other: in larger and higher resolution screens, elements with a fixed height and width will be smaller, and will have more space around to position other elements; in smaller and lower resolution display elements will be larger, and there is less space to position other elements.

It is best not to use fixed sizes and positions, but sizes and relative positions. It is also better to use simpler layouts as LinearLayout, and combine them together.

Juan C. V.
  • 537
  • 5
  • 19
0

FILL_PARENT (renamed MATCH_PARENT in API Level 8 and higher), which means that the view wants to be as big as its parent (minus padding) ...

fill_parent: The view should be as big as its parent (minus padding). This constant is deprecated starting from API Level 8 and is replaced by match_parent.

source

Community
  • 1
  • 1
pRaNaY
  • 24,642
  • 24
  • 96
  • 146