Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
371 views
in Technique[技术] by (71.8m points)

android - Explain the difference between drawable, drawable-ldpi, drawable-mdpi and drawable-hdpi

I have a rough idea of what each of these directories are for, but I'm not really clear on the concept and I have some specific questions.

For example, what are the target DPIs for each directory? When you create an asset, should it be at that target DPI or should it be at the more normal 72dpi screen DPI? If you're targeting multiple devices, is it ever appropriate to put a PNG in drawable or should you always have multiple versions slightly tailored to the specific screens?

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As the others have suggested, the Android online documentation has great articles on this. However, I'm going to try and list here some quick and helpful tips:

  1. Consider MDPI is 1. Then, LDPI is 0.75 and HDPI is 1.5. What that means is that if you have a drawable that is, say, 50x50 on a MDPI screen it will have to be ~37x37 on a LDPI screen and 75x75 on a HDPI screen, in order to appear at roughly the same physical size on each screen (i.e. 2cm if you put a ruler on the screen). Also, your computer screen is most probably MDPI, which is why it's recommended to start with MDPI drawables and then resize them: the physical size of the drawable will be very close between your computer screen and an MDPI Android device. If you view an HDPI drawable on your computer and on an HDPI device you will notice that it's much bigger (again, physically -- put a ruler on it style) on the PC screen.
  2. If you do not supply special drawables for each density, Android will scale the closest one available automatically.
  3. You should not consider the DPI of a device to have anything to do with screen size and/or number of pixels and/or resolution and/or aspect ratio. A device could be very small and have an HDPI screen or very large and have an LDPI screen. The whole point of this density-differentiation is to have things look the same size on all devices, not fit the same on all devices. For example, if a drawable fills the whole screen on one MDPI device do not expect it to do the same on another MDPI device. Also, do not expect to "see the same thing" on different DPI devices. Most HDPI devices actually have more space than lower DPI devices. For example, if a ListView can show 5 items on a MDPI device it might be able to show 6 items on an HDPI device, in spite of the fact that the ListView items have the same density-independent (i.e. 1.5 times larger on HDPI than on MDPI) height.

I might have gone a bit offtopic, but these are things I have learned in time by banging my head against them. Just trying to save someone else's headache :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...