Android supports different screen supporting different screens

Source: Internet
Author: User
Supporting different screenspreviousnext

This lesson teaches you
  1. Create different layouts
  2. Create different bitmaps
You shoshould also read
  • Designing for multiple screens
  • Supporting multiple screens
  • Iconography Design Guide

The screen size and pixel density of Android devices are different. Your applications run on Android devices of different sizes or pixel density. Therefore, you should add some alternative resources, so that your applications have excellent interfaces on devices of different sizes and pixel density.

  • Generally, there are four sizes: small, normal, large, and xlarge.
  • Four types of density: low (ldpi), medium (mdpi), high (hdpi), extra high (xhdpi)

Different layout files and images stated for different screens should be placed in different directories, just like strings in different languages.

In addition, you should also consider the orientation of the screen (horizontal or vertical screen). Therefore, many applications should modify the layout file so as to have a good user experience in different screen directions.

Create different layout files

To ensure that your application performs well on different screen sizes, you should design a layout for each screen size, and save each layout file in the appropriate resource directory-<screen_size>Suffix. For example, layout files designed for large screens are stored inres/layout-large/.

Note:Android can automatically scale the layout to fully adapt to your screen. Therefore, you do not need to consider the absolute size of UI elements when designing layout files for different screens, instead, we should focus on the layout structure that affects user experience, such as the size and location of important views.

For example, this project includes a default layout file and an alternative layout file for the large screen:

MyProject/    res/        layout/            main.xml        layout-large/            main.xml

The names of these files must be identical, but the content is not required. To provide a suitable UI for screens of different sizes.

In general, you can simply use layout file names in your app.

@Override protected void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     setContentView(R.layout.main);}

The system selects the layout file under the appropriate directory based on the device size. For more information about how to select the right resources, see
Providing resources guide.

In another example, this project provides a layout for the horizontal screen

MyProject/    res/        layout/            main.xml        layout-land/            main.xml

Default layout Filelayout/main.xmlUsed for Portrait screen.

If you want to provide a portrait layout file for a large screen, the layout file requires two modifiers: large and land:

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:Android and later versions provide an advanced function for defining screen sizes, using density-independent pixels to set the smallest width and height for the UI, so as to specify resources for screens of different sizes.

This section does not involve this new technology. For more information, see designing for multiple screens.

Create different bitmap

Appropriate bitmap resources should be scaled for screens of different density: low, medium, high and extra-high. this allows your applications to have good graphic quality and performance on screens of different density.

To create these images, you must first create original image resources in the vector format, and then use the following parameters to scale and create images for screens of each density.

  • Xhdpi: 2.0
  • Hdpi: 1, 1.5
  • Mdpi: 1.0 (baseline)
  • Ldpi: 0.75

This means that if you create a 100 x image for the xhdpi device, you should create a x image for the hdpi and a x image for the mdpi device, creates 75x75 images for ldpi devices,

Then, save these image files in the appropriate drawable resource directory:

MyProject/    res/        drawable-xhdpi/            awesomeimage.png        drawable-hdpi/            awesomeimage.png        drawable-mdpi/            awesomeimage.png        drawable-ldpi/            awesomeimage.png

When you use@drawable/awesomeimageThe system selects an appropriate image based on the screen density.

Note:Ldpi resources are not required. If hdpi resources are provided, the system reduces the hdpi resources by half to match the ldpi screen.

For more information, see the iconography design guide.

Http://developer.android.com/training/multiscreen/screensizes.html

 

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.