ScreenOrientation, Sensor, Automatical, Flip, Manifest

Quickly share your Android Code Snippets here...

ScreenOrientation, Sensor, Automatical, Flip, Manifest

Postby plusminus » Thu Nov 06, 2008 4:41 am

JAVA:
void setRequestedOrientation(int requestedOrientation) Change the desired orientation of this activity.

Parameter is one of these (from the [font=Courier New]android.content.pm.ActivityInfo[/font] Class):
int SCREEN_ORIENTATION_BEHIND Constant corresponding to behind in the screenOrientation attribute. 3
int SCREEN_ORIENTATION_LANDSCAPE Constant corresponding to landscape in the screenOrientation attribute. 0
int SCREEN_ORIENTATION_NOSENSOR Constant corresponding to sensor in the screenOrientation attribute. 5
int SCREEN_ORIENTATION_PORTRAIT Constant corresponding to portrait in the screenOrientation attribute. 1
int SCREEN_ORIENTATION_SENSOR Constant corresponding to sensor in the screenOrientation attribute. 4
int SCREEN_ORIENTATION_UNSPECIFIED Constant corresponding to unspecified in the screenOrientation attribute. -1
int SCREEN_ORIENTATION_USER Constant corresponding to user in the screenOrientation attribute. 2


XML:
This snippet rotates an Activity automatically based on the accelerometer.
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. android:screenOrientation="sensor"
Parsed in 0.000 seconds, using GeSHi 1.0.8.4

Sample AndroidManifest.xml:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. ...
  2.         <activity android:screenOrientation="sensor" android:name=".ui.map.WhereAmIMap" android:label="@string/app_name_whereami">
  3.             <intent-filter>
  4.                 <action android:name="android.intent.action.DEFAULT" />
  5.                 <category android:name="android.intent.category.VIEW" />
  6.             </intent-filter>
  7.         </activity>
  8. ...
Parsed in 0.001 seconds, using GeSHi 1.0.8.4

Don not forget to implement onRestoreInstanceState and onSaveInstanceState to make the user-experience fluent :!:
SDK Version compatible: 1.0 (maybe prior versions too)
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Return to Code Snippets for Android

Who is online

Users browsing this forum: No registered users and 6 guests