Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Screen orientations inAndroidBy Nataraj Manjahttp://natdroid.blogspot.in/
Types of screen orientation in android• port: Device is in portrait orientation (vertical)• land: Device is in landscape o...
Example: 1This code is used when you have 2 different layout file that isportrait and landscape.protected void onCreate(Bu...
Example: 2Check screen orientation in runtime.public void onConfigurationChanged(Configuration newConfig) {super.onConfigu...
Example: 3Switching to landscape mode in Android Emulator.Ctrl+F11
• Ctrl+F11
Example: 4Switching to landscape or portrait mode in eclipse.Landscape.Press this tabNATDROID
• PortraitPress this tabNATDROID
Example: 5How to lock phone orientation in Android to preventlandscape mode?By adding the following code in your AndroidMa...
Example: 6Making the application to support for all devicesresolution.You can add following code in your AndroidManifest.x...
Screen orientations in android
Upcoming SlideShare
Loading in …5
×

Screen orientations in android

Android Screen orientations and changing of modes from landscape to portrait or vice versa.

  • Login to see the comments

Screen orientations in android

  1. 1. Screen orientations inAndroidBy Nataraj Manjahttp://natdroid.blogspot.in/
  2. 2. Types of screen orientation in android• port: Device is in portrait orientation (vertical)• land: Device is in landscape orientation(horizontal)This can change during the life of yourapplication if the user rotates the screen.Some example:
  3. 3. Example: 1This code is used when you have 2 different layout file that isportrait and landscape.protected void onCreate(Bundle savedInstanceState) {int result = this.getResources().getConfiguration().orientation;if (result == 1){//set content view to portraitsetContentView(R.layout.portrait);}else{//set content view to landscape}setContentView(R.layout.landscape);}}
  4. 4. Example: 2Check screen orientation in runtime.public void onConfigurationChanged(Configuration newConfig) {super.onConfigurationChanged(newConfig);// Checks the orientation of the screenif (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();} else if (newConfig.orientation ==Configuration.ORIENTATION_PORTRAIT){Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();}}
  5. 5. Example: 3Switching to landscape mode in Android Emulator.Ctrl+F11
  6. 6. • Ctrl+F11
  7. 7. Example: 4Switching to landscape or portrait mode in eclipse.Landscape.Press this tabNATDROID
  8. 8. • PortraitPress this tabNATDROID
  9. 9. Example: 5How to lock phone orientation in Android to preventlandscape mode?By adding the following code in your AndroidManifest.xml.<activityandroid:name="com.example.display.InfoActivity"android:configChanges="orientation|keyboardHidden"android:label="@string/app_name"android:screenOrientation="landscape" />(com.example.display.InfoActivity) its your actvity name.
  10. 10. Example: 6Making the application to support for all devicesresolution.You can add following code in your AndroidManifest.xml to support differentscreens.<supports-screensandroid:anyDensity="true"android:largeScreens="true"android:normalScreens="true"android:resizeable="true"android:smallScreens="true"android:xlargeScreens="true" />OR<supports-screens android:anyDensity="true" />

×