Android phone multi-resolution adaptation

Source: Internet
Author: User

The recent work on the adaptation of the Android screen is a bit of a prospect today. Take a little note.

Basic knowledge is not science, a lot of online. As a new contact with this person, the first to enter my brain, is from small to large various screens, small to watch, big to the street to see the billboard. Then make a distinction between these different sizes of screens by how they are used:

3.5 inches or less. Less mobile phones are available in this size and more wearable devices

3.5-7 inch this size range is mainly mobile

6 inches or less of the tablet. is also relatively small

The 6-11-inch range is mainly flat

Both the phone and tablet are in the hands of the device (can also be seen on the stand), with 7 inches as the size of the split point. This split point determines the layout of the interface, that is, less than 7 inches of the screen with a set of layouts, larger than 7 inches of the screen with another set of layouts (depending on the size of the screen or the use of the two to four sets of layout)

Since the project is currently only considered for use on mobile phones, so far just consider the 7-inch screen below, that is, just write a set of layout on the line. Later to do tablet words, and then write another layout.  Used to fragment. This is a bit off the subject, don't pull this.

Layout_width & Layout_height only with Match_parent.
It is obviously not possible to use PX. The same size of the screen, low-resolution screen display of the control large, high-resolution screen display of the control is small, with the resolution of the more and more large differences in the size of the control display more and more large.
It is also problematic to use wrap_content. Now the picture resources are placed in Drawable-x & Mipmap-x two directories.
Drawable put. 9 pictures and some selector, corner used to control these. 9 display style.
Mipmap put the picture resources. The back-X refers to ldpi, MDPI, hdpi, xhdpi, xxhdpi. A picture resource with different pixel densities under each directory. If you put resources under one directory. For example, under the XHDPI, consider the same size of the screen (mobile phone screen size difference is not much), then the high-resolution screen below the picture is relatively large, and in the low-resolution screen below the display of the picture is relatively small,  Because the Android system will xhdpi the picture below and then get the lower resolution screen to use below, so it becomes smaller. OK, so if these picture resources are placed under the lhdpi, then the lower resolution screen is clear, but the high-resolution screen below the display is very blurred, because the Android system will lhdpi the image below to enlarge and then get the high-resolution screen to use below. So the picture becomes bigger and it becomes blurred.

If you don't want the Android system to zoom in or out, use high-resolution images directly under the Mipmap directory.

Consider the size of the phone screen, different resolutions and different aspect ratios. In fact, for the fixed resolution of the aspect ratio, if the layout file is used relative layout, then the layout will not change. The rest is to take into account the different aspect ratio of the resolution.
For example, some common resolutions. {640*360} {960*540} {1280*720} {1920*1080} {2560*1440} These resolutions have a length-to-width ratio of 1.7777 ....
{1280*768} {800*480} These two aspect ratios are 1.666 ... {1280*800} {2560*1600} These two aspect ratios are 1.6
For these chaotic aspect ratios, the same layout shows the effect of stretching. The stretch effect is determined by the size of the length-width ratio.

Later, I would like to use Dimens to write the corresponding PX under different resolutions, and then use the Dimens directly in the layout, so that different models will be used on the various values. This allows for a different aspect ratio of the screen. But there are two problems with this. One is such a dimens too much, difficult to maintain, even if the mainstream resolution, encountered a resolution is not set Dimens phone, the effect is very bad. The second is that some of the phones under the row of control buttons are software-implemented, not directly on the hardware. This makes an impact on the resolution of the interface.
From 3.0 onwards, for the screen to adapt to the resolution of 1280*720, the previous way is to write a layout-1280x720 such a folder, which placed the corresponding Dimens file. And now to subtract a 48px (the height of the status bar), the name of the folder will be written layout-1232*720, and then put in the Dimens file, but I tested some machine found not read this file, found a problem, found that different system status bar height is not the same, If you want to use such a solution, you have to solve the problem that the status bar is not as high as before.   @[email protected]!!! You can actually set the height of this status bar in Values/dimens.xml, but I tested it.

The root of the problem is that the control cannot set a relative percentage on the length and width. Then think of the extended control to modify the paint, adding a relative percentage of the property. Such a thought, first go to the Internet to find whether people have had the same idea and realized, there really is! Refer to the following link:
http://blog.csdn.net/lmj623565791/article/details/46767825

The following is the use of this library. You encounter a problem with the problem:
Error:execution failed for task ': App:dexdebug '.
> com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:Process ' command ' C:\Program Files\java\jdk1.7.0_79\bin\java.exe ' finished with Non-zero exit value 2

This problem is due to a library conflict. That's all you need to do is to exclude the conflict library.

Let's comment out this library in Gradle.build.
Compile and run, no problem.  Open the Projname/.idea/libraries and save the file in this directory (to see which library is more than one). The reference library comment in the Gradle.build is then canceled. Then compile, the above problems, and then open the projname/.idea/libraries look at this time the directory is compared with just a few more files, such as more than three files:

The first file is a reference to the library, and the following two files are deleted in the Gradle.build, as

Run again, OK, no problem.

Android phone multi-resolution adaptation

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.