Android Portrait & Landscape Differeent Layouts
July 30, 2010 in Common Issue, emulator by Sasikumar
Today we are going to see about, How to use different layout when screen orientation changes from Portrait to Landscape or Landscape to Portrait.
For example :-
In portrait mode , the option page button will looks like nice when buttons are in one by one position.
But in landscape if we use the same process we need to have scrollview to see all the option button in the page.
To overcome this problem here is a easy solution.
In your res folder create two folders for Landscape 1) drawable-land 2) layout-land
drawable-land folder images is used when the phone orientation in landscape mode.
layout-land folder layout files is used when the phone orientation in landscape mode.

main.xml fopr portrait
<?xml version="1.0" encoding="utf-8"?> <LinearLayout android:id="@+id/LinearLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:gravity="center"> <Button android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button"></Button> <Button android:id="@+id/Button02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button"></Button> <Button android:id="@+id/Button03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button"></Button> <Button android:id="@+id/Button04" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button"></Button> </LinearLayout>
main.xml fopr Landscape
<?xml version="1.0" encoding="utf-8"?> <LinearLayout android:id="@+id/LinearLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:gravity="center"> <LinearLayout android:id="@+id/LinearLayout03" android:layout_width="wrap_content" android:layout_height="wrap_content"> <Button android:id="@+id/Button03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button"></Button> <Button android:id="@+id/Button04" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button"></Button> </LinearLayout> <LinearLayout android:id="@+id/LinearLayout02" android:layout_width="wrap_content" android:layout_height="wrap_content"> <Button android:id="@+id/Button02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button"></Button> <Button android:id="@+id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button"></Button> </LinearLayout> </LinearLayout>Android Portrait & Landscape Differeent Layouts


Thanks! I was wondering how this works. I haven’t needed to implement this yet, but I’m sure I will in the future! Saves me from some SDK / Google searches!
Hi,
How to handle different size streaming video view when screen orientation changes from Portrait to Landscape or Landscape to Portrait?
Asma,
Look at this example
http://www.androidpeople.com/android-how-to-handle-screen-orientation-change-issue/
Handling screen orientation when orientation changes from Portrait to Landscape or Landscape to Portrait.
it may help you
Hi Sasikumar Sir,
I want to change the orientation for video, may be that’s why it’s not working.But it’s ok.
My most urgent and important need is to make progress bar for streaming video. Still now the only streaming video link which is working for mp4 and 3gp in phone:
http://davanum.wordpress.com/2009/12/04/android-%E2%80%93-videomusic-player-sample-take-2/
Please help me to get rid out from this problem.
Asma.