做Android有段时间了,但是好多细节还没有深入理解,关于Android中drawable文件夹的使用理解的就不是很深入。
Android为开发者提供了两种解决适配问题的方法,第一种方式是使用dip的单位,另一种方法是使用不同的drawable文件夹,今天就详细说下不同文件夹的区别
Android中提供了三个存放图片的文件夹,分别为hdpi,mdpi,ldpi,google文档上说,Andriod系统会根据手机屏幕的大小及屏幕密度去选择不同文件夹下的图片资源,以此来实现在不同大小不同屏幕分辨率下适配的问题。
比如在一个低分辨率的手机上,Android就会选择ldpi文件夹下的图片,但是如果没有在ldpi的文件夹下找见相关的资源文件,Android系统会首先从hdpi文件夹中选择文件,然后对图片资源进行缩放处理,显示在屏幕上;如果hdpi文件夹下也没有的话,会在默认的drawable文件夹中寻找。
明白以上内容,就很好解释图片放错文件夹,显示大小不同的问题了。如图
图1
图2
出现图二的原因是将放在hdpi下的图片放到了默认的文件夹下
本身图片是同一张图片,由于没有在hdpi文件夹中找到对应图片,系统在默认文件夹下找见了图片资源,但是这时系统会认为改图适用于中等分辨率的屏幕上,如果直接放到高分辨率的手机上不能适配,所以系统会自动的将图片放大,所以虽然是同一张图片,但是现实出来就一个正常效果,一个放大效果。
同理,如果同一张图片,放置在ldpi的文件夹下,在低分辨率的手机上显示正常,但是如果放在hdpi文件夹中,系统认为该图是为高分辨率显示的,要将图片缩小处理,所以显示出来的效果就是图变小了。
所以我们在平时要注意,明明都是一张图片,只是放在不同的文件夹中,显示出来的效果就很不同,原因就是我们对Android还不够了解。
对了,我还有个疑问,就是布局文件中设置wrap_content时,view的大小的单位是dip还是px呢!!!
以下为google文档的描述
At runtime, the system ensures the best possible display on the current screen with the following procedure for any given resource:
- The system uses the appropriate alternative resource
Based on the size and density of the current screen, the system uses any size- and density-specific resource provided in your application. For example, if the device has a high-density screen and the application requests a drawable
resource, the system looks for a drawable resource directory that best matches the device configuration. Depending on the other alternative resources available, a resource directory with thehdpi
qualifier
(such asdrawable-hdpi/
) might be the best match, so the system uses the drawable resource from this directory.
- If no matching resource is available, the system uses the default resource and scales it up or down as needed to match the current screen size and density
The "default" resources are those that are not tagged with a configuration qualifier. For example, the resources indrawable/
are
the default drawable resources. The system assumes that default resources are designed for the baseline screen size and density, which is a normal screen size and a medium density. As such, the system scales default density resources up for high-density screens
and down for low-density screens, as appropriate.
However, when the system is looking for a density-specific resource and does not find it in the density-specific directory, it won't always use the default resources. The system may instead use one of the other density-specific resources
in order to provide better results when scaling. For example, when looking for a low-density resource and it is not available, the system prefers to scale-down the high-density version of the resource, because the system can easily scale a high-density resource
down to low-density by a factor of 0.5, with fewer artifacts, compared to scaling a medium-density resource by a factor of 0.75.
分享到:
相关推荐
Android开发中的drawable-(hdpi,mdpi,ldpi)和WVGA,HVGA,QVGA的区别以及联系
SVG -> drawable-xhdpi、drawable-hdpi、drawable-mdpi、drawable-ldpi Android SVG 资源生成器 未来证明您的资产并节省时间! 创建/查找一次,不用担心 DPI 存储桶。 此工具允许您将 SVG 文件用于您的 Android ...
Android应用图标大小自适应,多屏幕支持
"ldpi", "mdpi", "hdpi", "xhdpi","xxhdpi", "xxxhdpi" 比如我的美工人员设计了一个图片适合 xhdpi 分辨率的手机,我可以通过AndroidDrawable将这个xhdpi转换成 "ldpi", "mdpi", "hdpi", "xhdpi","xxhdpi", ...
在开发过程中,由于使用模拟器测试了程序,在首次运行后会将res文件夹下的图片资源文件(如drawable-hdpi、drawable-ldpi和drawable-mdpi)拷贝到bin文件夹下。在替换资源图片后,eclipse并不清楚是否有图片改变,...
适应不同的分辨率 drawable-hdpi、drawable-mdpi 、drawable-ldpi. drawable-xhdpi .drawable-large drawable-small drawable-xlarge
在导入模拟器图片时,要特别注意你的图片的大小与比例 首先 要想模拟器全屏,必须在manifest.xml中进行设置: android:theme="@android:style/... drawable-ldpi 中density= 120,所以你必须导入 240*360 px 的图片
Android的自动图像大小调整器 该程序会自动调整android项目的图像大小。 该程序不会覆盖现有文件和文件夹,也不会删除提供的图像。... 该程序将创建5个新文件夹(drawable-ldpi,drawable-mdpi,drawable-hdpi,draw
│ ├─drawable-hdpi │ │ icon.png │ │ │ ├─drawable-ldpi │ │ icon.png │ │ │ ├─drawable-mdpi │ │ icon.png │ │ │ ├─layout │ │ main.xml │ │ │ └─values │ strings.xml │ └─src...
Android中支持许多资源,包括图片(Bitmap),对应于bitmap的文件夹是drawable,除了drawable,还有drawable-ldpi、drawable-mdpi、drawable-hdpi、drawable-xhdpi、drawable-xxhdpi等,同一张图片放到上面不同的...
在res/drawable-hdpi或res/drawable-ldpi或res/drawable-mdpi目录下,加下你要显示的图片,最好后缀是为.png的,然后修改AndroidManifest.xml文件,里面有这样一行代码<application android:icon="@drawable/icon" ...
在导入图片时必须注意你的模拟器的分辨率和density 例如 ,我的模拟器的尺寸为HVGA,即分辨率为320*480,density为160. 所以在导入图片时应该注意... drawable-ldpi 中density= 120,所以你必须导入 240*360 px 的图片
用法 adg [file] [reference size] [--outname] [--outwidth][--outheight] [--outdir] [--genoutdir] [--aspectratio] [--scaleoutside] [--ldpi] [--mdpi] [--hdpi] [--xhdpi] [--help]缩放的工作原理图像将根据...
文件夹 PATH 列表 卷序列号为 78014EE3 3CD2:D088 C:. │ 041501 (1).png │ 041501 (2).png │ javaapk.com文件列表生成工具.bat │ JavaApk源码说明.txt │ 点这里查看更多优质源码~.url │ 目录列表.txt │ ├─...
Android Drawable Converter项目旨在通过提供一个能够自动将可绘制对象转换为其他密度版本(如ldpi,mdpi,hdpi,xhdpi)的工具来帮助您。 安装 要使用此项目,您可以在下载页面上下载“ Android Drawable ...
在android开发的过程中我们经常因为没有好的美工图片失真,这样使界面看起来要逊色很多,有的时候可能我们会想在drawable-hdpi,ldpi,mdpi下放不同分辨率的图片,这样虽然可以有效避免图片失真,但是这样一是麻烦而是...
│ ├── drawable-hdpi │ ├── drawable-ldpi │ ├── drawable-mdpi │ ├── layout │ │ ├── dialog.xml │ │ └── rename.xml │ └── values │ ├── fileendings.xml │ └──...
推荐使用Android 4.0 以上版本的SDK: target=android-14 一、工程目录结构 根目录 ├ source ├ LICENCE.txt ├ README.md 目录简要解释 根目录 ├ source --源代码 ├ LICENCE.txt --协议 ├ README.md --项目...
① drawable-*dpi(比如ldpi,hdpi,mdpi,xdpi)(dpi,dots per inch;或PPI,pixels per inch) 定义Android应用中需要的不同分辨率的资源文件 ② values Android应用界面上需要显示各类文本标签的文字信息...
在android程序中,在drawable中设置好图标后,但结果在小米2可没有显示出来,但在我自己的htc中和模拟器中显示正常。后来发现小米的dpi不一样。 后来发现,android为了适应不同的分辨率和dpi,加载了一系列的图标。 ...