Android的drawable文件夹的说明

However there are the specific folders drawable-ldpi, 'drawable-mdpi', 'drawable-hdpi' and even 'drawable-xhdpi' together with the basic 'drawable' folder.

在Android中有三种特殊的文件夹drawable-ldpi, drawable-mdpi, drawable-hdpi 有时甚至有drawable-xhdpi, 以及基本文件夹drawable

Maybe you are familiar with all those, but I will repeat their usage patterns, because I have a feeling this might be failing you. The ldpi, mdpi, hdpi and xhdpi mean low, medium, high and extra high dpi - different screen resolutions. Android has a special way of determining the hardware characteristics of the device you are running on and thus mapping it to the most relevant: ldpi, mdpi, hdpi or xhdpi.

可能你已经非常熟悉他们了,但是我仍将重复它们的使用模式,因为我感觉你会在这上面犯错误。ldpi, mdpi, hdpi and xhdpi意味着低、中等、高、和非常高像素的不同的屏幕解决方案。Android有一种特殊的方法通过决定你将要运行的硬件设备的属性来将硬件设备映射到最相屏幕解决方案:ldpi, mdpi, hdpi,或是xhdpi

When it comes to a place in which you need an image say image.png it first searches for drawable-mdpi/image.png (if it has determined your device to be mapping to mdpi). If such image is not found it goes and tries drawable/image.png and will rescale it if found. And that's it, if those two searches have failed and you have supplied the image in some of the other resolutions' folder it will not use it. This means that if you install the app on xhdpi device and have supplied only ldpi and mdpi image on such device no relevant image will be found.

当它来到一个地方,在那里需要一个图片,例如image.png时,它首先查找drawable-mdpi/image.png (假设它已经决定你的设备将要映射到mdpi),如果这个文件没有找到,它将尝试查找drawable/image.png 如果找到了就缩放它。也就是说,如果那两个查找都失败了而你已经提供了这张图片且放在了其它图片像素解决方案的文件夹内,系统将不会使用它。这意味着如果你安装你的app到xhdpi,并且只为此设备提供了ldpi和mdpi图片,那么相关的图片将会找不到.

这种问题将会导致的错误:

android.content.res.Resources$NotFoundException: Resource is not a Drawable 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值