Android layout of the screen switch

Source: Internet
Author: User
Tags config

By default, the Onconfigurationchanged event triggers when the screen changes from a vertical to a horizontal screen, which by default reloads the screen and displays the same screen as the horizontal screen, which can have 2 problems.

* Layout problems, in the vertical display of the layout to the horizontal screen due to the width and height of the changes all will affect the layout (unless you customize 2 sets of images and then add a judge in the horizontal screen how to show, in the vertical screen how to display), of course, the easiest way is in The androidmanifest.xml of the project is found in the activity you specify plus

o Only Vertical screen display (android:screenorientation= "Portrait")

o Only Horizontal screen display words (android:screenorientation= "Landscape")

* Screen Reload Problem: By default, the switch will reload the screen, lead to unnecessary waste of resources, and more seriously, the data maintained on the screen (especially the game) has been reset (of course, you can save the data to the database or to a text file before resetting), how to avoid Reload the screen when you switch,

o First of all, find the activity you specified in Androidmanifest.xml, plus android:configchanges= "Orientation|keyboardhidden."

O then overload the Onconfigurationchanged event in the logical processing of the activity (part of the code), referring to the specific code:

+ @Override
public void onConfigurationChanged(Configuration config) {
super.onConfigurationChanged(config);
}

In the onconfigurationchanged, decide whether to display a horizontal or vertical screen and then Setcontentview

There's a way.

The Layout-port and Layout-land are established under the Res folder, and the layout files (with the same name) of the vertical and horizontal screens are automatically invoked.

The above can be simple to control the display of your app screen and in the same way that the display mode does not change the screen will not reload the screen, that is, optimize your app at the same time the user experience also improved accordingly.

Source: http://blog.csdn.net/muyu114/archive/2011/04/20/6334875.aspx

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.