Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

specify different layouts for portrait and landscape orientations?

I've specify two separate layout xml files for an activity, one for Portrait in res/layout folder and one for Landscape in res/layout-land folder. my actual problem is that when i launch application in portrait mode it takes ui from layout and instantly i rotate my phone it doesn't take xml from layout-land folder it takes ui from layout folder and if i launch my app in landscape mode it takes xml from layout-land folder and instantly rotate my to portrait mode it take xml from layout-land ui doesn't change to portrait ui.

can any buddy tell me whats the problem is there any setting required for that plz help me to solve this issue .

Thanks in advance .

    this is my landscape ui xml

        <?xml version="1.0" encoding="utf-8"?>
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/widget57"
        android:layout_width="400dp"
        android:layout_height="400dp"
        android:layout_gravity="center|center_vertical"
        android:layout_marginTop="30dp"
        android:orientation="vertical" >

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="40dp" >

            <TextView
                android:id="@+id/txtName"
                android:layout_width="90dp"
                android:text="@string/UserName" />

            <EditText
                android:id="@+id/edName"
                android:imeOptions="actionNext|actionDone"
                android:paddingRight="10dp"
                android:singleLine="true"
                android:width="240dp" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/txtPass"
                android:layout_width="90dp"
                android:text="@string/PassWord" />

            <EditText
                android:id="@+id/edPass"
                android:imeOptions="actionGo"
                android:paddingRight="10dp"
                android:password="true"
                android:singleLine="true"
                android:width="240dp" />
        </TableRow>

         <LinearLayout
            android:id="@+id/widget57"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="center"
            android:orientation="vertical" >

            <Button
                android:id="@+id/btnLogin"
                android:layout_width="150dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="10dp"
                android:text="@string/btn_GO"
                android:textSize="19sp" >
            </Button>

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="30dp"
                android:text="CoinOp Solutions"
                android:textSize="30sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="10dp"
                android:text="Version 0.1" />
        </LinearLayout>


    </TableLayout>

    this is my Portrait ui

        <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/widget57"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/txt_Required"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="15dp"
            android:text=""
            android:textColor="#ffff0000" >
        </TextView>

        <TextView
            android:id="@+id/txtName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="15dp"
            android:text="@string/UserName" >
        </TextView>

        <EditText
            android:id="@+id/edName"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:imeOptions="actionNext|actionDone"
            android:singleLine="true"
            android:textSize="18sp" >
        </EditText>

        <TextView
            android:id="@+id/txtPass"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:text="@string/PassWord" >
        </TextView>

        <EditText
            android:id="@+id/edPass"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:imeOptions="actionGo"
            android:maxLines="1"
            android:password="true"
            android:singleLine="true"
            android:textSize="18sp" >
        </EditText>

        <LinearLayout
            android:id="@+id/widget57"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="center"
            android:orientation="vertical" >

            <Button
                android:id="@+id/btnLogin"
                android:layout_width="150dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="10dp"
                android:text="@string/btn_GO"
                android:textSize="19sp" >
            </Button>

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="30dp"
                android:text="CoinOp Solutions"
                android:textSize="30sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="10dp"
                android:text="Version 0.1" />
        </LinearLayout>

    </LinearLayout>

My manifest file

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package=""
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <application
        android:debuggable="true"
        android:icon="@drawable/coinop"
        android:label="@string/app_name"
        android:theme="@style/CustomTheme" >
        <activity
            android:name=".LoginActivity"
            android:configChanges="orientation"
            android:label="@string/app_name"
            android:windowSoftInputMode="stateVisible|adjustPan" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".ShowDbList"
            android:configChanges="orientation"
            android:label="@string/app_name"
            android:windowSoftInputMode="adjustPan" >
        </activity>
        <activity
            android:name=".Menu"
            android:configChanges="orientation"
            android:label="@string/app_name"
            android:windowSoftInputMode="adjustPan" >
        </activity>
like image 964
Sachin Gurnani Avatar asked Dec 21 '22 00:12

Sachin Gurnani


2 Answers

You have android:configChanges="orientation" in your manifest. According to the doc configChanges contains list of actions that you'll handle manually yourself.

If you remove the android:configChanges="orientation" the layout will be changed when you rotate the phone. Otherwise you're supposed to handle it yourself.

like image 52
Mariusz Jamro Avatar answered Apr 06 '23 01:04

Mariusz Jamro


Not sure if this helps, but u can try (if u didn't already):

  1. in the activity that uses the layout, override onConfigurationChanged and setContentView again.
  2. remove android:configChanges="orientation" for the activity that uses the layout
like image 34
Andrei Avatar answered Apr 06 '23 01:04

Andrei