Android dynamically specifies the screen orientation

Source: Internet
Author: User

Recently, the development involves dynamically specifying screen orientation, which is summarized as follows:

Activity screen attributes include the following:

Activityinfo. screen_orientation_landscape, // specify the landscape
Activityinfo. screen_orientation_portrait, // specify the portrait Screen

Activityinfo. screen_orientation_user, // user orientation

Activityinfo. screen_orientation_nosensor, // not affected by gravity

Activityinfo. screen_orientation_sensor_landscape, // Dynamic screen Conversion

Activityinfo. screen_orientation_sensor_portrait, // converts the portrait screen dynamically.
Activityinfo. screen_orientation_full_sensor, // orientation based on gravity Transformation

After learning about the activity attributes, you can set them accordingly.

It can be executed in the oncreate () method.

Setrequestedorientation (activityinfo. screen_orientation_full_sensor );

This enables full screen redirection.

Colleagues can also use methods

@ Override
Public void onconfigurationchanged (configuration newconfig ){
// Int type = This. getresources (). getconfiguration (). orientation;

If (newconfig. Orientation = configuration. orientation_landscape ){
// Switch to the landscape
} Else if (newconfig. Orientation = configuration. orientation_portrait ){
// Switched to the portrait Screen
}

Super. onconfigurationchanged (newconfig );
}

Listen to screen changes to respond.

Related Article

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.