Android Screen Summary (GO)

Source: Internet
Author: User

Android Screen Summary (GO)

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: After configchanges= "Orientation|keyboardhidden", after the screen switch will not go to execute the Oncreat function, but will call Onconfigurationchanged (), So we can control the switching of the screen.
or in the Res directory to establish the Layout-land and Layout-port directory, the corresponding layout file is 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 setrequestedorientation in the code ( Activityinfo.screen_orientation_landscape);. If you want it to always be a vertical display, just set android:screenorientation= "Portrait" in the configuration file, or setrequestedorientationin the code ( activityinfo.screen_orientation_portrait);.

When the start is horizontal screen, the horizontal screen, vertical screen, the vertical screen, mobile phone switching screen can not be used.
Step One: Append android:screenorientation= "sensor" android:configchanges= "to the Mainfest.xml"orientation| Keyboardhidden"

The second step: 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 > height) {
orientation = Activityinfo.screen_orientation_landscape;
} else {
orientation = 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 let it back from another screen, and then re-screen layout, as long as in the Onresume () in the settings on the line, but this only supports the screen only one layout.

Android Screen Summary (GO)

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.