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

前端 未结 4 1367
一生所求
一生所求 2020-12-05 15:24

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

相关标签:
4条回答
  • 2020-12-05 16:04

    Due to different screen size and resolutions, Android lets you arrange your drawable images according to folders. Images for high dpi displays should be placed in hdpi and similarly mdpi and ldpi. The default folder for the drawables is drawables if the operating system does not match any dpi category or the resources is not found in special dpi directories the system picks the resource from the drawables directory.

    The size are not exact but upto 130dpi it is considered small, from 130 to 180 it can be considered mdpi, from 180 to 200 it can be considered as hdpi and the higher is classified as xdpi.

    http://developer.android.com/guide/practices/screens_support.html

    0 讨论(0)
  • 2020-12-05 16:17

    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 :)

    0 讨论(0)
  • 2020-12-05 16:23

    Sorry but Android has a great online doc with examples so for this type of question the answer is:

    http://developer.android.com/guide/practices/screens_support.html

    0 讨论(0)
  • 2020-12-05 16:25

    There are no exact DPI values for each folder. Every folder is related to some range. See here: http://developer.android.com/guide/practices/screens_support.html

    These directories must hold drawable resources optimized for some screen density. You can hold just one drawable for HDPI or any other, but on devices with other DPI settings image will be resized somehow and it will take time/resources. Also low DPI image will look poor on devices with HDPI.

    0 讨论(0)
提交回复
热议问题