Android learning route (18) Supports different devices-Supports different screens

Source: Internet
Author: User

Android learning route (18) Supports different devices-Supports different screens

Android uses two common attributes: size and density to classify the device screens. You need to first predict what screen devices your application will be installed on, including the screen size and density. In this way, you need to provide some optional resource classes so that your applications can be best displayed on devices on different screens.

  • There are four common dimensions: small, normal, large, xlarge
  • There are also four common density types: low (ldpi), medium (mdpi), high (hdpi), extra high (xhdpi)

    To declare different la S and images for different screens, you need to place these optional resources in different directories. This is similar to how to support multiple languages.

    Considering the screen direction configuration in different screen sizes, many applications can achieve the best user experience by changing the layout in different directions.

    Create different la s

    To make your application have a good user experience on different screen sizes, you should create a unique XML layout file for each screen size you want to support. Each layout file should be stored in the appropriate resource directory with the directory name- Suffix. For example, the name of a layout directory that stores large screens isres/layout-large/.

    Tip:The Android system automatically scales the layout to adapt to the screen correctly. Therefore, you do not need to worry about the actual size of the UI elements you have designed for different la S, note the layout structure that affects the user experience (for example, the layout of an important layout is relative to the layout size and position next to it ).

    For example, this project includes a default layout directory and a layout directory for large screens:

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

    The file names must be identical, but their content must be different to provide the best UI display for different screen sizes.

    Simple reference layout in applications:

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

    The system adds the layout files in the appropriate layout directory based on the screen size of the device.

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.