Work with Portrait and Landscape Layout

Posted: 27/03/2013 in Android

Android Portrait & Landscape Differeent Layouts

 

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

<br />&lt;?xml version="1.0" encoding="utf-8"?&gt;</p><p>&lt;LinearLayout android:id="@+id/LinearLayout01"<br />android:layout_width="fill_parent" android:layout_height="fill_parent"<br />xmlns:android="http://schemas.android.com/apk/res/android"<br />android:orientation="vertical" android:gravity="center"&gt;<br />&lt;Button android:id="@+id/Button01" android:layout_width="wrap_content"<br />android:layout_height="wrap_content" android:text="Button"&gt;&lt;/Button&gt;<br />&lt;Button android:id="@+id/Button02" android:layout_width="wrap_content"<br />android:layout_height="wrap_content" android:text="Button"&gt;&lt;/Button&gt;<br />&lt;Button android:id="@+id/Button03" android:layout_width="wrap_content"<br />android:layout_height="wrap_content" android:text="Button"&gt;&lt;/Button&gt;<br />&lt;Button android:id="@+id/Button04" android:layout_width="wrap_content"<br />android:layout_height="wrap_content" android:text="Button"&gt;&lt;/Button&gt;<br />&lt;/LinearLayout&gt;</p><p>

main.xml fopr Landscape

<br />&lt;?xml version="1.0" encoding="utf-8"?&gt;</p><p>&lt;LinearLayout android:id="@+id/LinearLayout01"<br />android:layout_width="fill_parent" android:layout_height="fill_parent"<br />xmlns:android="http://schemas.android.com/apk/res/android"<br />android:orientation="vertical" android:gravity="center"&gt;<br />&lt;LinearLayout android:id="@+id/LinearLayout03"<br />android:layout_width="wrap_content" android:layout_height="wrap_content"&gt;<br />&lt;Button android:id="@+id/Button03" android:layout_width="wrap_content"<br />android:layout_height="wrap_content" android:text="Button"&gt;&lt;/Button&gt;<br />&lt;Button android:id="@+id/Button04" android:layout_width="wrap_content"<br />android:layout_height="wrap_content" android:text="Button"&gt;&lt;/Button&gt;<br />&lt;/LinearLayout&gt;<br />&lt;LinearLayout android:id="@+id/LinearLayout02"<br />android:layout_width="wrap_content" android:layout_height="wrap_content"&gt;<br />&lt;Button android:id="@+id/Button02" android:layout_width="wrap_content"<br />android:layout_height="wrap_content" android:text="Button"&gt;&lt;/Button&gt;<br />&lt;Button android:id="@+id/Button01" android:layout_width="wrap_content"<br />android:layout_height="wrap_content" android:text="Button"&gt;&lt;/Button&gt;<br />&lt;/LinearLayout&gt;<br />&lt;/LinearLayout&gt;</p><p>

Advertisements

Trả lời

Mời bạn điền thông tin vào ô dưới đây hoặc kích vào một biểu tượng để đăng nhập:

WordPress.com Logo

Bạn đang bình luận bằng tài khoản WordPress.com Đăng xuất / Thay đổi )

Twitter picture

Bạn đang bình luận bằng tài khoản Twitter Đăng xuất / Thay đổi )

Facebook photo

Bạn đang bình luận bằng tài khoản Facebook Đăng xuất / Thay đổi )

Google+ photo

Bạn đang bình luận bằng tài khoản Google+ Đăng xuất / Thay đổi )

Connecting to %s