0

I have set up the layout as follows, it is the vertical format, and when i change it to the horizontalorientation it totally messes up bad.

enter image description here

But when I change the orientation of the device, it becomes like this:

enter image description here

Can anyone please help me to fix this ?

And the XML code for the following is follows:

    <?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:gravity="center" >

    <Button
        android:id="@+id/bBackfromInquiry"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:background="@drawable/back" />

    <Button
        android:id="@+id/bSubmit"
        android:layout_width="90dp"
        android:layout_height="90dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:background="@drawable/mail_us" />

    <EditText
        android:id="@+id/etMailbody"
        android:layout_width="wrap_content"
        android:layout_height="150dp"
        android:layout_above="@+id/bSubmit"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:ems="10"
        android:hint="@string/inqhintComments" />

    <EditText
        android:id="@+id/etPhone"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/textView5"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="27dp"
        android:ems="10"
        android:hint="@string/inqhintPhone"
        android:inputType="phone" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/bBackfromInquiry"
        android:layout_alignBottom="@+id/bBackfromInquiry"
        android:layout_marginLeft="17dp"
        android:layout_toRightOf="@+id/bBackfromInquiry"
        android:text="@string/buttonInquiry"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/textView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:text="@string/inqComments"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <EditText
        android:id="@+id/etName"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/bBackfromInquiry"
        android:ems="10"
        android:hint="@string/inqhintName"
        android:inputType="textPersonName" >

        <requestFocus />
    </EditText>

    <EditText
        android:id="@+id/etEmail"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/etName"
        android:layout_marginTop="15dp"
        android:ems="10"
        android:hint="@string/inqhintEmail"
        android:inputType="textEmailAddress" />

</RelativeLayout>
Manan Gupta
  • 491
  • 1
  • 7
  • 11

5 Answers5

1

try this xml code in your device

<?xml version="1.0" encoding="UTF-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/sc"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/LinearLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical" >

        <LinearLayout
            android:id="@+id/LinearLayout1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/bBackfromInquiry"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:background="@drawable/back" />

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="15dp"
                android:text="@string/buttonInquiry"
                android:textAppearance="?android:attr/textAppearanceLarge" />
        </LinearLayout>

        <EditText
            android:id="@+id/etName"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="15dp"
            android:hint="@string/inqhintName"
            android:inputType="textPersonName" />

        <EditText
            android:id="@+id/etEmail"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="15dp"
            android:hint="@string/inqhintEmail"
            android:inputType="textEmailAddress" />

        <EditText
            android:id="@+id/etPhone"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="15dp"
            android:hint="@string/inqhintPhone"
            android:inputType="phone" />

        <TextView
            android:id="@+id/textView5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:layout_marginTop="15dp"
            android:text="@string/inqComments"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <EditText
            android:id="@+id/etMailbody"
            android:layout_width="wrap_content"
            android:layout_height="150dp"
            android:layout_gravity="left"
            android:layout_marginTop="15dp"
            android:hint="@string/inqhintComments" />

        <Button
            android:id="@+id/bSubmit"
            android:layout_width="90dp"
            android:layout_height="90dp"
            android:layout_gravity="right"
            android:layout_marginTop="15dp"
            android:background="@drawable/mail_us" />
    </LinearLayout>

</ScrollView>
Vaibhav Agarwal
  • 4,499
  • 3
  • 19
  • 20
0

Sometimes such things happen when you omit

android:layout_below="@id/xyz"

But in this case I think there's just not enough room for all the fields on the screen. I think a a ScrollView (probably with a vertical LinearLayout) could help you.

UPDATE (after the XML is posted):

Try to rewrite it using only layout_below. Currently it looks like one view is at the top, the 2nd one is below it, the 3rd one is in the center, but there's no guarantee that the 2nd and the 3rd views will not overlap.

18446744073709551615
  • 16,368
  • 4
  • 94
  • 127
0

my suggestion is create another xml for landscape in res directory like res/layout-land for perfect view in landscape mode or you can put scroll view in xml

Mohit
  • 93
  • 7
  • Okay, i got it. But how to implement the same in java file. Means i am still unclear about it that how to connect the xml in a way that the same layout loads with different orientation when rotated. And how to connect one java code class with two layouts. If you know what i mean. – Manan Gupta Feb 20 '14 at 05:45
  • it automatically reloads the xml file the main things is that you should put same name of xml in layout folder like if you have main.xml in layout folder than put same file name in res/layout-land/main.xml on run time if device configurations change android pickup the xml from landscape folder if device in landscape mode – Mohit Feb 20 '14 at 05:51
  • or if you want manually handel landscape or portatit mode than refer this link http://stackoverflow.com/questions/13411391/android-device-onconfigurationchanged-event-does-not-handling-orientation – Mohit Feb 20 '14 at 05:54
0

@MananGupta : I will suggest you to create xml for landscape mode too....

  1. Create a folder in your resouce:-

res / layout-land

and add xml file under it...

But make sure to give name of the xml file same as that of in portrait mode since same is going to be referred but for different modes.

For more information go with this Link

Community
  • 1
  • 1
Namrata
  • 1,683
  • 1
  • 17
  • 28
0

Create a layout-land directory and put the landscape version of your layout XML file in that directory. Complete info given here

http://developer.android.com/guide/practices/screens_support.html

Diffy
  • 2,339
  • 3
  • 25
  • 47