Android : Memaksa Display Android tetap Potrait / tetap Lanscape


Programmatically

public class Orientation extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

//—change to landscape mode—
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

   //To change to portrait mode, use the ActivityInfo.SCREEN_ORIENTATION_PORTRAIT constant:
}
}

Besides using the setRequestOrientation() method, you can also use the android:screenOrientation attribute on the <activity> element in AndroidManifest.xml as follows to fix the activity to a certain orientation:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="net.learn2develop.UIExample" android:versionCode="1" android:versionName="1.0.0"> 
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".UIActivity" android:screenOrientation="landscape" android:label="@string/app_name"> 
<intent-filter> <action android:name="android.intent.action.MAIN" /> 
<category android:name="android.intent.category.LAUNCHER" /> 
</intent-filter>
</activity>
</application> 
</manifest> 

The above example fixes the activity to a certain orientation (landscape in this case) and prevents the activity from being destroyed; that is, the activity will not be destroyed and the onCreate event will not be fired again when the orientation changes.


/* http://www.devx.com/wireless/Article/40792/1954  */

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s