I have created a WiFi Widget. Its size is decreasing while changing the orientation from Portrait to Landscape.
The layout I am using is given below.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center" >
<ImageView
android:id="@+id/wifi_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<!--<TextView
android:id="@+id/wifi_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:layout_marginTop="5dip"
android:layout_marginLeft="35dip"
android:layout_gravity="center_horizontal" />
-->
</LinearLayout>
<TextView
android:id="@+id/wifi_off"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:layout_gravity="center_horizontal"
android:layout_marginTop="15dip"
android:layout_marginLeft="25dip"
android:textColor="@android:color/white"
android:textSize="15dip"
/>
<TextView
android:id="@+id/wifi_notconnected"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:layout_marginTop="43dip"
android:layout_marginLeft="35dip"
android:layout_gravity="center_horizontal"
android:textSize="14dip" />
<TextView
android:id="@+id/wifi_connecting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:layout_marginTop="8dip"
android:layout_marginLeft="33dip"
android:layout_gravity="center_horizontal"
android:textSize="14dip" />
<TextView
android:id="@+id/wifi_obtaining"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dip"
android:layout_marginLeft="40dip"
android:textColor="@android:color/white"
android:textSize="10dip"
/>
<TextView
android:id="@+id/wifi_on"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dip"
android:layout_marginLeft="40dip"
android:textColor="@android:color/white"
android:textSize="10dip"
/>
<ImageView
android:id="@+id/wifi_signal_strength"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<FrameLayout android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginTop="5dip">
<ImageView
android:id="@+id/wifi_circle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/onpress_network_info_null"
android:src="@drawable/toggle"
/>
<ImageView
android:layout_alignRight="@+id/wifi_circle"
android:id="@+id/wifi_square"
android:layout_width="85dip"
android:layout_height="60dip"
android:background="@drawable/network_info_null"
android:src="@drawable/togglenetwork"/>
</RelativeLayout>
</FrameLayout>
</FrameLayout>
If you want this layout both Portrait and Landscape then you write hard code on oncreate like this:-
There will be a time you need to define your application GUI both in landscape and portrait (just rotate the phone).
Luckily, every droid has the built-in function to detect layout type. What you need to implement is:
Create two main.xml files for layout in both case: landscape and portrait.
Put those two main.xml in resources according to its type:
Just build and try your application GUI in runtime.
In case, you want to detect the timing when layout type change and you want to do some additional works in coding, you might wanna follow these steps:
Add android:configChanges=”orientation” to AndroidManifest.xml
Detect the orientation change:
Details
If you want only portrait, then
If you want only landscape, then
If you want more information, Please go to these links
http://developer.android.com/resources/articles/faster-screen-orientation-change.html
http://developer.android.com/guide/topics/manifest/activity-element.html#screen
StackOverflow search