Question

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

Was it helpful?

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.

OTHER TIPS

Hi You need to create two different layout for landscape and portrait mode try this and create a new folders has

 res/
    layout/              # default (portrait)
        main.xml
    layout-land/         # landscape
        main.xml
    layout-large/        # large (portrait)
        main.xml
    layout-large-land/   # large landscape
        main.xml

I hope this help you

By default, the layouts in /res/layout are applied to both portrait and landscape.

If you have for example

/res/layout/main.xml

Add a new folder /res/layout-land, copy main.xml into it and make the needed adjustments.

  1.)  create folder /res/layout-land (here you will keep your landscape adjusted layouts)
  2.)  copy home.xml there
  3.)  make necessary changes to it

For more information go with this link

Also see http://www.androidpeople.com/android-portrait-amp-landscape-differeent-layouts and http://www.devx.com/wireless/Article/40792/1954 for some more options.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top