Android-Support for different devices-support different screens

Source: Internet
Author: User

Android-Support for different devices-support different screens

Android generally classifies device screens in two broad categories: size and resolution. The app should consider size and resolution when running on the device. Similarly, you should include different resources to adapt the app to different screen sizes and resolutions.

    • Overall there are four sizes: small, normal, big, super big

    • And four resolutions: low resolution (LDPI), medium resolution (MDPI), high resolution (HDPI), ultra high resolution (XHDPI)

To declare different layouts and mutations for different screens, you need to put different resources in different folders, just as you would for different languages.

Also note that the orientation of the screen (horizontal screen) should be considered when considering the screen size, so many apps need to adjust the layout in each direction to optimize the user experience.

Create a different layout

In order to optimize the user experience on different screen sizes, you should create a separate XML file for each screen size that you want to support. Each layout should be saved to the corresponding resource folder, named with the end of the <screen_size> suffix. For example, a layout file created for a large screen should exist Res/layout-large

Note: Android automatically stretches the layout to fit the screen. For layouts with different screen sizes, there is no need to consider the absolute size of the UI controls, and you can focus more on the layout structure that affects the user experience (such as the size and position of the important view relative to its child view).

For example, this project contains the default layout and the layout of the large screen

myproject/

res/

layout/

Main.xml

layout-large/

Main.xml

The file names must be exactly the same, and their content is different in order to accommodate different screens of different UI sizes.

Referencing the layout file in the app and as usual

@Override  protected void onCreate (Bundle savedinstancestate) { super.oncreate (savedinstancestate);  Setcontentview (R.layout.main); 5}   

The system loads the layout file from the corresponding layout folder according to the screen size that the app runs. More information on how Android chooses the right resources is presented in the providing resource.

Another example of this project is how to choose a horizontal screen layout resource.

myproject/

res/

layout/

Main.xml

layout-land/

Main.xml

By default, the Layout/main.xml file is used on the vertical screen.

If you need to provide a special layout for a horizontal screen, including a large screen, then you need to use large and land identification:

myproject/

res/

layout/#default (Portrait)

Main.xml

layout-land/#landscape

Main.xml

layout-large/#large (Portrait)

Main.xml

layout-large-land/#large Landscape

Main.xml

Note: Android3.2 and above support some advanced methods to define the screen size, which allows the width of the element's smallest height to define the resource for the screen size. This will not drop to this new technology. For more information, see Designing for multiple Screens.

Create a different picture

You should provide an appropriate picture resource that can be stretched for each resolution. This allows for good drawing quality and effect on screens of various resolutions.

In order to generate these images, you should provide a vector diagram and provide a picture for each of the following resolutions:

    • xhdpi:2.0

    • hdpi:1.5

    • mdpi:1.0 (Baseline)

    • ldpi:0.75

This means that if you provide a 200*200 image for the xhdpi device, you should provide the same resources for the other resolutions: 150*150 for HDPI, and for MDPI, and for ldpi.

Then, put these files under the corresponding resource folder:

myproject/

res/

drawable-xhdpi/

Awesomeimage.png

drawable-hdpi/

Awesomeimage.png

drawable-mdpi/

Awesomeimage.png

drawable-ldpi/

Awesomeimage.png

Any time you reference @drawable/awesomeimage, the system chooses the appropriate image based on the screen resolution.

Note: Low-resolution (LDPI) resources are not always needed, and when hdpi resources are provided, the system shrinks them in half to fit the ldpi screen

For more tips and an introduction to the icon for your app, check out the iconography design guide.

Reprint: http://www.cnblogs.com/fengquanwang/p/3142549.html

Android-Support for different devices-support different screens

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.