set Screen Orientation - Android User Interface

Android examples for User Interface:Screen Orientation

Description

set Screen Orientation

Demo Code


//package com.java2s;
import android.app.Activity;
import android.content.pm.ActivityInfo;

public class Main {
    public static final int ORIENTATION_DEVICE = 0;
    public static final int ORIENTATION_PORTRAIT = 1;
    public static final int ORIENTATION_LANDSCAPE = 2;
    private static int mOrientation = 0;

    public static void setScreenOrientation(Activity act, int mode) {
        mOrientation = mode;/*from  w w w. jav  a2  s  . c  o m*/
        switch (mOrientation) {
        case ORIENTATION_DEVICE:
            act.setRequestedOrientation(act.getRequestedOrientation());
            break;
        case ORIENTATION_PORTRAIT:
            act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
            break;
        case ORIENTATION_LANDSCAPE:
            act.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            break;
        }//switch
    }
}

Related Tutorials