Cheap VPS & Xen Server


Residential Proxy Network - Hourly & Monthly Packages

Screen Orientation


The screenOrientation is the attribute of activity element. The orientation of android activity can be portrait, landscape, sensor, unspecified etc. You need to define it in the AndroidManifest.xml file. For example:

  1. <activity
  2.             android:name=“com.example.screenorientation.MainActivity”
  3.             android:label=“@string/app_name”
  4.             android:screenOrientation=“landscape”
  5.             >

The common values for screenOrientation attribute are as follows:

Value Description
unspecified It is the default value. In such case, system chooses the orientation.
portrait taller not wider
landscape wider not taller
sensor orientation is determined by the device orientation sensor.

Android landscape mode screen orientation example

activity_main.xml

File: activity_main.xml
  1. <RelativeLayout xmlns:androclass=“http://schemas.android.com/apk/res/android”
  2.     xmlns:tools=“http://schemas.android.com/tools”
  3.     android:layout_width=“match_parent”
  4.     android:layout_height=“match_parent”
  5.     android:paddingBottom=“@dimen/activity_vertical_margin”
  6.     android:paddingLeft=“@dimen/activity_horizontal_margin”
  7.     android:paddingRight=“@dimen/activity_horizontal_margin”
  8.     android:paddingTop=“@dimen/activity_vertical_margin”
  9.     tools:context=“.MainActivity” >
  10.     <Button
  11.         android:id=“@+id/button1”
  12.         android:layout_width=“wrap_content”
  13.         android:layout_height=“wrap_content”
  14.         android:layout_marginLeft=“66dp”
  15.         android:layout_marginTop=“73dp”
  16.         android:text=“Button”
  17.         android:onClick=“onClick”
  18.          />
  19.     <EditText
  20.         android:id=“@+id/editText1”
  21.         android:layout_width=“wrap_content”
  22.         android:layout_height=“wrap_content”
  23.         android:layout_centerHorizontal=“true”
  24.         android:ems=“10” />
  25. </RelativeLayout>

Activity class

File: MainActivity.java
  1. package com.example.f;
  2. import android.os.Bundle;
  3. import android.app.Activity;
  4. import android.view.Menu;
  5. import android.view.View;
  6. import android.view.View.OnClickListener;
  7. import android.widget.Button;
  8. import android.widget.EditText;
  9. public class MainActivity extends Activity{
  10.     EditText editText1;
  11.     Button button1;
  12.     @Override
  13.     protected void onCreate(Bundle savedInstanceState) {
  14.         super.onCreate(savedInstanceState);
  15.         setContentView(R.layout.activity_main);
  16.         editText1=(EditText)findViewById(R.id.editText1);
  17.         button1=(Button)findViewById(R.id.button1);
  18.     }
  19.     public void onClick(View v) {
  20.         editText1.setText(“O android”);
  21.     }
  22. }

AndroidManifest.xml

File: AndroidManifest.xml
  1. <?xml version=“1.0” encoding=“utf-8”?>
  2. <manifest xmlns:androclass=“http://schemas.android.com/apk/res/android”
  3.     package=“com.example.screenorientation”
  4.     android:versionCode=“1”
  5.     android:versionName=“1.0” >
  6.     <uses-sdk
  7.         android:minSdkVersion=“8”
  8.         android:targetSdkVersion=“16” />
  9.     <application
  10.         android:allowBackup=“true”
  11.         android:icon=“@drawable/ic_launcher”
  12.         android:label=“@string/app_name”
  13.         android:theme=“@style/AppTheme” >
  14.         <activity
  15.             android:name=“com.example.screenorientation.MainActivity”
  16.             android:label=“@string/app_name”
  17.             android:screenOrientation=“landscape”
  18.             >
  19.             <intent-filter>
  20.                 <action android:name=“android.intent.action.MAIN” />
  21.                 <category android:name=“android.intent.category.LAUNCHER” />
  22.             </intent-filter>
  23.         </activity>
  24.     </application>
  25. </manifest>

Output:

screenorientation

 

Comments

comments