Android Set Horizontal screen, disable screen rotation, activity reset

Source: Internet
Author: User

1. Setting the screen orientation

When the orientation of the screen is specified (not screen_orientation_unspecified), the screen does not rotate automatically

There are 2 ways to control the screen orientation:

1.1 modifying androidmanifest.xml

in Androidmanifest.xml's activity, add:Horizontal screen:
           android:screenorientation= "Landscape" vertical screen:           android:screenorientation= "Portrait"

1.2 setrequestedorientation

Horizontal screen:

Setrequestedorientation (Activityinfo.screen_orientation_landscape);

Vertical screen:

Setrequestedorientation (activityinfo.screen_orientation_portrait);


Activityinfo:

Int

Screen_orientation_behind

Constant corresponding to behind in the screenorientation attribute.

int

screen_orientation _full_sensor

CONSTANT CORRESPONDING TO  fullsensor  IN THE  screenorientation  attribute.

int

screen_orientation _full_user

CONSTANT CORRESPONDING TO  fulluser  IN THE  screenorientation  attribute.

int

screen_orientation _landscape

constant corresponding to  landscape  IN THE  screenorientation  attribute.

int

screen_orientation _locked

constant corresponding to  locked  IN THE  screenorientation  attribute.

int

screen_orientation _nosensor

constant corresponding to  nosensor  IN THE  screenorientation  attribute.

int

screen_orientation _portrait

constant corresponding to  portrait  IN THE  screenorientation  attribute.

int

screen_orientation _reverse_landscape

CONSTANT CORRESPONDING TO  Reverselandscape  IN THE  screenorientation  attribute.

int

screen_orientation _reverse_portrait

CONSTANT CORRESPONDING TO  reversePortrait  IN THE   attribute.

int

screen_orientation _sensor

constant corresponding to  sensor  IN THE  screenorientation  attribute.

int

screen_orientation _sensor_landscape

CONSTANT CORRESPONDING TO  sensorLandscape  IN THE   attribute.

int

screen_orientation _sensor_portrait

CONSTANT CORRESPONDING TO  sensorPortrait  IN THE   attribute.

int

screen_orientation _unspecified

constant corresponding to  unspecified  IN THE  screenorientation  attribute.

int

screen_orientation _user

constant corresponding to  user  IN THE  screenorientation  attribute.

int

screen_orientation _user_landscape

CONSTANT CORRESPONDING TO  userLandscape  IN THE   attribute.

Int

Screen_orientation_user_portrait

Constant corresponding to userportrait in the screenorientation attribute.




2. Disable screen rotation and reset activity

The activity.oncreate method is forced to be called after the screen is rotated, so the Activity is reset

Forbidden Method:

Modify androidmanifest.xml

android:configchanges= "Orientation"




Android Set Horizontal screen, disable screen rotation, activity reset

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.