Understand the relationship between DPI and resolution in Android, and talk about how Android makes the UI fit for all phones

Source: Internet
Author: User

http://blog.csdn.net/ueryueryuery/article/details/20048401

Recently I am making an interface, the UI gives the transduction is 1280x720 this resolution, the given unit is PX (pixels).

I put the original in the drawable-xhdpi, and then began to adjust the layout (I was the default 1dp=2px). Put this layout on a 720P TV, found completely deformed, strange and incomparable, watching the TV density, found that the goods is 1, this is a MDPI equipment!!!

Then I began to think, 720P of transduction, to put in xhdpi here, but some equipment itself is mdpi and the like, then this resolution and DPI what is the relationship?

The landlord first checked the following basic concepts:

1.dpi:dots per inch, an inch of the number of pixels, this value is the device's own decision, is written dead, of course, there are manufacturers themselves engaged in a density=1.25, I do not know what to say ...

The following table is provided by Google:

How many are there in an inch? We used density to tell.
ldpi 120dpi 0.75
mdpi 160dpi 1
hdpi 240dpi 1.5
xhdpi 320dpi 2

2.DIP (that is, we use the DIP/DP): device independent pixel, devices independent pixels, we do not directly use PX, but use dp,1 px = 1DP * Density (dpi).

There is no problem with resolution at all ... I don't think there's any relationship between DPI and resolution ...

Hakiyu discussed for a while and finally understood the following two questions:

1. Why a 720P device, take mdpi in the picture, but 720P transduction to put in xhdpi?

A: This is entirely based on the mainstream phone to decide, such as the current mainstream is 480p/hdpi mobile phone, then, in the UI, will take 720P as xhdpi, take 320P as MDPI, take 240P as ldpi, such a set of plans to cut out.

If the mainstream phone resolution becomes the 720p/hdpi phone, then, in the UI, will take 480P as MDPI, take 1080P as xhdpi, and so on.

As for Google's recommendation: Take the maximum resolution you have at your fingertips as a benchmark, make the clearest diagram (XHDPI), and then scale to make hdpi, MDPI, and ldpi. So from the principle, where the 720P transduction can be changed according to the device.

2. If the 720P transduction is in xhdpi, but I have a mdpi/720p device on hand, what should I do?

(Suppose your app supports all the wonderful resolutions, and you've cut 4 sets of diagrams (LDPI~XHDPI) and written a set of layouts in layout)

A: If you consider the relationship between DPI and resolution yourself, you will find that their relationship is not related ... So this problem, my solution (everyone's) is, let multiple sets of dimens to help us solve this problem.

480p 600p 720p 1080p
mdpi values-sw480dp-mdpi values-sw600dp-mdpi values-sw720dp-mdpi values-sw1080dp-mdpi
hdpi values-sw480dp-hdpi ... ... ...
xhdpi values-sw480dp-xhdpi ... ... ...

In your Res folder, create these folders, and then put in a dimens.xml, in this way, you can deal with all the resolution situation.

Example: If there is a 100x50 (pixel) size control on the original image (1280x720), then for a normal hdpi/800x480 device, it should be set to the size (DP) as:

Length: (100/720*480/1.5) DP = 45DP (rounding up)

Width: (50/720*480/1.5) DP = 23DP

The two values are written in the Values-sw480dp-hdpi/dimens.xml, and the proportions of the graphs are the same as the original.

The size of the mdpi/1280x720 device that I have just listed is:

Length: (100/720*720/1) = 100DP;

Width: (50/720*720/1) = 50DP;

The two values are written in values-sw720dp-mdpi, and the proportions of the graphs are the same as the original.

3. I'm not going to have black iOS, and if iOS has a few more resolutions, is the iOS developer going to freak out?

A: For now, I am happy to answer you: Yes! iOS layout is the same way as the absolute layout of Android, and it does not wrap_content and match_parent these ways, wait until iOS 10 and waist, I see you do the iOS development of swollen, haha.

In conclusion, I hope this post can help some students who have doubts about the Android layout ~

Understand the relationship between DPI and resolution in Android, and talk about how Android makes the UI fit for all phones

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.