Lao Li share: Android phone test (1)

Source: Internet
Author: User

Android screen adaptation has been torturing us these developers, this article is based on Google's official documents, a comprehensive and in-depth explanation of the reasons for Android screen adaptation, Key concepts, solutions and best practices, I believe if you can seriously study this article, For Android screen adaptation, you'll have something to gain!

    • Why the Android screen fits
    • Important Concepts
      • Screen size
      • Screen resolution
      • Screen pixel density
      • Dpdipdpisppx
      • mdpihdpixdpixxdpi
    • Solution Solutions
      • Supports various screen sizes
        • Using Wrap_contentmatch_parentweight
        • Disable absolute layout with relative layout
        • Using qualifiers
          • Using Dimension Qualifiers
          • Use the minimum width qualifier
          • Using layout aliases
          • Using the screen orientation qualifier
          • Using auto-stretch bitmaps
      • Supports various screen densities
        • Using non-density-restricted pixels
        • Provide alternate bitmap
      • Implement an adaptive user interface process
        • Determining the current layout
        • Respond to current layout
        • Reusing clips from other activities
        • Handling Screen configuration changes
      • Best practices
        • About HD Design Dimensions
        • The ScaleType property of ImageView
        • Dynamic settings
      • More Resources

Why the Android screen fits

Before we learn how to make a screen fit, we need to understand why Android needs to be screen adapted.

Thanks to the openness of the Android system, any user, developer, OEM or operator can customize Android to the way they want it to be.

But to what extent does this "fragmentation" arrive?

In 2012, Opensignalmaps (OSM) released its first Android fragmentation report, and statistics show that

    • In 2012, there were 3997 Android-enabled devices.
    • In 2013, there were 11868 Android-enabled devices.
    • In 2014, there were 18796 Android-enabled devices.

The following picture shows the severity of today's Android fragmentation problem because every rectangle in the picture represents an Android device.

With the proliferation of devices that support Android (mobile phones, tablets, TVs, watches), device fragmentation, brand fragmentation, system fragmentation, sensor fragmentation, and screen fragmentation continue to deepen. And what we're going to talk about today is the fragmentation of the screen, which has a bigger impact on our development.

The image below is the size of the Android screen, where the size of the blue rectangle represents the size, and the color depth represents the percentage.

And the corresponding, is the following picture. This figure shows the screen size and the ratio that iOS devices need to fit.

Of course, this image is just the size of the 4,4s,5,5c,5s and the tablet, and it should now be added with the new iphone6 and plus, but it's still too far off compared to the extent of the Android screen fragmentation.

For detailed statistical data, please check here

Now you should know why you're adapting the Android screen? Screen size so much, in order to let us develop the program can be more beautiful display in different sizes, resolutions, pixel density (these concepts I will explain in detail below) on the device, it will be in the process of development, as to how to deal with, this is our topic today.

But before we go into the subject, let's explore one more thing: the size of the Android device, from a few inches of smartphones to 10-inch tablets to dozens of-inch digital TVs, which devices should we fit in?

In fact, this problem should not be considered, because for devices with the same pixel density, the higher the pixel, the larger the size, so we can change the idea of the problem from a simple size to the pixel size and pixel density angle.

At the beginning of 2014, the Friends of the league accounted for more than 5% of the 6 mainstream resolution, it can be seen that the highest proportion of the 480*800,320*480 equipment has also accounted for a large proportion, but compared with the data of six months ago, the ratio of medium and low resolution (320*480, 480*800) is decreasing, The ratio of medium to high resolution is increasing continuously. Although the proportion of each resolution is changing, the overall trend remains the same, or six, but the resolution is constantly improving.

So, as long as we try to match these resolutions, we can work on most phones.

Of course, this is just the adaptation of the phone, for the tablet device (TV can also be seen as a tablet), we also need some other processing.

Well, so far we've figured out why Android development is going to fit, and what we should be able to match, and then finally get to the point!

First, we need to learn a few important concepts first.

Important Concepts

What is screen size, screen resolution, screen pixel density?
What is DP, dip, DPI, SP, px? What is the relationship between them?
What is MDPI, hdpi, xdpi, xxdpi? How to calculate and differentiate?

We will cover these concepts in the following sections.

Screen size

Screen size refers to the length of the diagonal of the screen, in inches, 1 inches = 2.54 centimeters

For example, common screen sizes are 2.4, 2.8, 3.5, 3.7, 4.2, 5.0, 5.5, 6.0, etc.

Screen resolution

Screen resolution refers to the number of pixels in the horizontal portrait, in px,1px=1 pixels. Generally in portrait pixels * transverse pixels, such as 1960*1080.

Screen pixel density

Screen pixel density refers to the number of pixels per inch, in dpi, which is the abbreviation for dot per inch. Screen pixel density is related to screen size and screen resolution, in the case of single change, the smaller the screen size, the higher the resolution, the greater the pixel density, the lower the inverse.

DP, dip, DPI, SP, px

PX We should be more familiar with, the front resolution is in pixels, in most cases, such as UI design, Android native API will be the PX as a unified unit of measurement, such as to obtain a higher screen width.

Dip and DP is a meaning, are density independent pixels abbreviation, that is, density-independent pixels, as we said above, DPI is the screen pixel density, if there is 160 pixels in an inch, this screen pixel density is 160dpi, then in this case, How is DP and PX converted? In Android, the rule is 160dpi, 1dip=1px, if the density is 320dpi, then 1dip=2px, and so on.

If the same is to draw a 320px line, 480*800 resolution on the phone display as 2/3 screen width, on the 320*480 phone is full full screen, if using DP units, at both resolutions, 160DP is displayed as the average length of the screen. This is why, in Android development, you should try to use DP instead of PX when writing layouts.

The SP, or scale-independent pixels, is similar to DP, but can be indented based on the text size preference, which is the Queen's Unit for setting the font size.

MDPI, hdpi, xdpi, xxdpi

In fact, there is a ldpi, but as the mobile device configuration is constantly upgrading, this pixel density device is very rare, where it is now suitable for the need not to consider.

MDPI, hdpi, xdpi, xxdpi are used to modify the Drawable folder and the values folder in Android to distinguish between images and dimen values in different pixel densities.

So how do you differentiate it? Google's official designation is differentiated according to the following criteria:

name pixel density range
mdpi 120dpi~160dpi
hdpi 160dpi~240dpi
xhdpi 240dpi~320dpi
xxhdpi 320dpi~480dpi
xxxhdpi 480dpi~640dpi

In the development, we need to put the appropriate size of the picture in the appropriate folder. The following is an example of an icon design.

When designing icons, the five main pixel densities (MDPI, HDPI, XHDPI, xxhdpi, and xxxhdpi) should be scaled according to the 2:3:4:6:8 scale. For example, the size of a boot icon is 48x48 DP, which means that on MDPI's screen its actual size should be 48x48 px, its actual size on the HDPI screen is 1.5 times times MDPI (72x72 px), and its actual size on the xdpi screen is MDPI 2 Times (96x96 px), and so on.

Although Android also supports low-pixel density (ldpi) screens, it does not bother to do so, and the system automatically shrinks the HDPI size icon to 1/2 for matching.

The corresponding size for each screen density of the icon

screen Density icon Size
mdpi 48x48px
hdpi 72x72px
xhdpi 96x96px
xxhdpi 144x144px
xxxhdpi 192x192px
Solution supports various screen sizes using wrap_content, match_parent, weight

To ensure the flexibility of the layout and to accommodate screens of various sizes, you should use "Wrap_content" and "match_parent" to control the width and height of some view components.

With "Wrap_content", the width or height of the view is set to the minimum size required to fit the content in the view, and "Match_parent" is called "fill_parent" at levels below the API level 8 ) expands the component to match the dimensions of its parent view.

If you use the "Wrap_content" and "match_parent" dimension values instead of the hard-coded dimensions, the view will use only the space or expansion that you want to fill the available space accordingly. This method allows the layout to properly accommodate various screen sizes and screen orientations.

Lao Li share: Android phone test (1)

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.