Saturday, 3 January 2015

Portrait or landscape screen in Android

The screen orientation of an Android application can be locked to portrait or landscape mode. It is relatively easy to set the screen orientation by using the screenOrientation property in the manifest file. Each activity to be locked will need to have screenOrientation property added.

To set the orientation to portrait mode. You can use portrait property like below.

<activity android:name=".MainActivity" android:screenOrientation="portrait" />

If you want to set the orientation to landscape mode. You can use the landscape property like below.
<activity android:name=".MainActivity" android:screenOrientation="landscape" />

The screen orientation can also be set programmatically with code using this below.
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Or this below.
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

0 comments:

  COPYRIGHT © 2014 · ILIKE2FLASH · Theme by Ourblogtemplates

Back to TOP