Drawable-hdpi、Drawable-mdpi、Drawable-ldpi Android

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3263265/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 09:21:36  来源:igfitidea点击:

Drawable-hdpi, Drawable-mdpi, Drawable-ldpi Android

androidimage

提问by Paresh Mayani

I was working on Android 1.5, but I have now moved to the latest version. So there is only one "drawable" folder in Android 1.5, but now there are three different folders for storing images in the Android project.

我在 Android 1.5 上工作,但我现在已经转移到最新版本。所以在Android 1.5中只有一个“drawable”文件夹,但现在Android项目中有三个不同的文件夹用于存储图像。

And I have found some articles for these three folders that says

我发现这三个文件夹的一些文章说

  1. hdpi means High-dpi
  2. mdpi means medium-dpi
  3. ldpi means low-dpi
  1. hdpi 表示高 dpi
  2. mdpi 表示中等 dpi
  3. ldpi 表示低 dpi

But what is the exact purpose of these three folders and when should I use a particular folder to store images in?

但是这三个文件夹的确切用途是什么,我什么时候应该使用特定的文件夹来存储图像?

回答by Neha Mangla

To declare different layouts and bitmaps you'd like to use for the different screens, you must place these alternative resources in separate directories/folders.

要声明要用于不同屏幕的不同布局和位图,您必须将这些替代资源放在不同的目录/文件夹中。

This means that if you generate a 200x200image for xhdpidevices, you should generate the same resource in 150x150for hdpi, 100x100for mdpi, and 75x75for ldpidevices.

这意味着如果您200x200xhdpi设备生成图像,您应该在150x150for hdpi100x100formdpi75x75for ldpidevices 中生成相同的资源。

Then, place the files in the appropriate drawable resource directory:

然后,将文件放在适当的可绘制资源目录中:

MyProject/
    res/
        drawable-xhdpi/
            awesomeimage.png
        drawable-hdpi/
            awesomeimage.png
        drawable-mdpi/
            awesomeimage.png
        drawable-ldpi/
            awesomeimage.png

Any time you reference @drawable/awesomeimage, the system selects the appropriate bitmap based on the screen's density.

每当您引用 时@drawable/awesomeimage,系统都会根据屏幕的密度选择适当的位图。

回答by jigar

I got one good solution. Here I have attached it as the image below. So try it. It may be helpful to you...!

我得到了一个很好的解决方案。在这里,我将其附加为下图。所以试试吧。可能对你有帮助...!

Enter image description here

在此处输入图片说明