Search code examples
androidlayoutscreen-orientation

Android form orientation change issue


Hi am trying to design a layout for a password change activity. I have made it, but when the screen orientation changes it looks weird.

for landscape mode it looks good and i have designed the layout in that graphical mode with relative layout and my edittext fields are center aligned and my textviews are left aligned to it. while i change it to portrait , the edittext are center aligned and my textview dont have space to fit in screen. I don't have much reputations to post my screenshots. So please understand it and help me

how can i design it for looking good at both orientations

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/textView1"
    android:layout_alignParentBottom="true"
    android:layout_alignRight="@+id/imageButton1"
    android:layout_below="@+id/imageButton2"
    android:layout_marginTop="15dp"
    android:background="@color/white" >

    <EditText
        android:id="@+id/currentPwd"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="100dp"
        android:background="@drawable/pwd_txt_box"
        android:ems="10"
        android:inputType="textPassword" >

        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/currentPwd"
        android:layout_alignBottom="@+id/currentPwd"
        android:layout_marginRight="42dp"
        android:layout_toLeftOf="@+id/currentPwd"
        android:text="@string/current_password"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <EditText
        android:id="@+id/newPwd"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/currentPwd"
        android:layout_marginTop="24dp"
        android:layout_toRightOf="@+id/textView2"
        android:background="@drawable/pwd_txt_box"
        android:ems="10"
        android:inputType="textPassword" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/newPwd"
        android:layout_alignBottom="@+id/newPwd"
        android:layout_alignLeft="@+id/textView2"
        android:text="@string/new_password"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <EditText
        android:id="@+id/confirmPwd"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/newPwd"
        android:layout_below="@+id/newPwd"
        android:layout_marginTop="26dp"
        android:background="@drawable/pwd_txt_box"
        android:ems="10"
        android:inputType="textPassword" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/confirmPwd"
        android:layout_alignBottom="@+id/confirmPwd"
        android:layout_alignLeft="@+id/textView3"
        android:text="@string/confirm_password"
        android:textAppearance="?android:attr/textAppearanceMedium" />

</RelativeLayout>

this is my xml layout code


Solution

  • Create layout-land in res folder.Paste your xml in it and adjust your layout for landscape in this folder and for portrait use simple layout folder and do changes for portrait in it.