Android Screen Summary

Source: Internet
Author: User


The activity will re-execute the Oncreat function after the screen switch, but add the
android:screenorientation= "user" Android to the Android project Mainfest.xml: Configchanges= "Orientation|keyboardhidden" after the
after the screen switch will not go to execute oncreat function, but will call Onconfigurationchanged (), So we can control the switching of the screen.
or the Layout-land and Layout-port directories are created in the Res directory, the corresponding layout files are unchanged. Layout-land is the horizontal screen of the layout,layout-port is the vertical screen layout.


If you want it to always be a horizontal display, just set android:screenorientation= "Landscape" in the configuration file,
or in the code Setrequestedorientation (Activityinfo.screen_orientation_landscape);.
If you want it to always be a vertical display, just set android:screenorientation= "Portrait" in the configuration file,
or setrequestedorientation in your code ( activityinfo.screen_orientation_portrait);.

 

When you start a horizontal screen, the horizontal screen, the vertical screen of the vertical screen, mobile phone switching screen can not be used.
First step: Append android:screenorientation= "sensor" android:configchanges= "Orientation|keyboardhidden" to Mainfest.xml

Step Two: Get the length and width of the screen, and compare the variables to set the screen.

Display display = Getwindowmanager (). Getdefaultdisplay (); int width = display.getwidth (); int height = display.getheight (); if (Width >=else= activityinfo.screen_orientation_portrait;}


Step Three: Append This.setrequestedorientation (morientation) to the onconfigurationchanged () function.

@Override  Public void onconfigurationchanged (Configuration newconfig) {super. onconfigurationchanged (newconfig);  This . Setrequestedorientation (morientation);}


When you cut to another frame, you return to the original screen, it is still horizontal or vertical. Want to get it back from another screen, and then re-screen layout,
As long as in the Onresume () in the setting, but this only supports the screen only one layout.

Android Screen Summary

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.