Android: Landscape | portrait switchover

Source: Internet
Author: User

You canConfigure screen discovery in androidmanifest. xml. Add this line to <activity> Android: screenorientation = "Landscape/portrait"

 

In Android, the activity is restarted when the screen is switched. You can save the status of the current activity before the activity is destroyed and load the configuration when the activity is created again, in progress, the game will not automatically restart)

 

When the screen changes to a horizontal screen, the system will callOncreateMethod, you can put the following method in your oncreate to check the current direction, and then let your setcontentview load different layout XML.

 

If (this. getresources (). getconfiguration (). Orientation = configuration. orientation_landscape ){

 

Log. I ("info", "Landscape ");

 

}

 

Else if (this. getresources (). getconfiguration (). Orientation = configuration. orientation_portrait ){

 

Log. I ("info", "portrait ");

 

}

 

In addition, the activity is restarted every time the screen direction is switched in Android. Therefore, you should save the status of the current activity before the activity is destroyed and load the configuration when the activity is created again, in progress, the game will not automatically restart! To avoid restarting the activity during screen conversion, you can re-define the direction in the androidmanifest. xml file (addAndroid: configchanges = "keyboardhidden | orientation"Attribute), and control it based on the override onconfigurationchanged (configuration newconfig) method of the activity, so that the activity will not be restarted during screen conversion, but will call onconfigurationchanged (configuration newconfig) this Hook method.

 

Why?Android: configchanges = "orientation" is not supported? I only use "orientation" and will still call the oncreate method.

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.