Search code examples
androidandroid-layoutandroid-orientation

Android screen orientation use different xmls (switching/rotating screen landscape and portrait)


I want to develop an android application for perfectly screen design arranged for portrait and landscape modes. and should have to give the screen orientation facility to user. how to change two xml files of the application when change the screen orientation of the device?


Solution

  • create another layout folder called layout-Land under the res folder. copy all landscape xml files to that layout -Land folder with the same name. Recheck all portrait xml files are in the layout folder. add android:configChanges="orientation" to the manifest

     <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>