简体   繁体   English

将图像保存在单个可绘制文件夹中的缺点(hdpi,mdpi或默认值)

[英]Drawbacks of keeping images into a single drawable folder (hdpi, mdpi or default)

I looked into several questions and answers but I still don't know exactly what could be the consequences of what I am doing on my app: 我调查了几个问题和答案,但我仍然不完全知道我在我的应用程序上进行的操作可能会带来什么后果:

I setup a background image on my main activity, and I added this line to be sure the image will be displayed over the whole screen: setScaleType(ScaleType.FIT_XY) (my images can be a little stretched without any problem, it cannot be seen thanks to the textures used). 我在主要活动上设置了背景图像,并添加了以下行以确保图像将显示在整个屏幕上: setScaleType(ScaleType.FIT_XY) (我的图像可以稍稍拉伸而不会出现任何问题,无法看到感谢使用的纹理)。

For now I only added the images in the xhdpi folder, since this density is the highest I plan to handle. 现在,我仅将图像添加到xhdpi文件夹中,因为此密度是我计划处理的最高密度。 Considering the images are automatically resized according to the screen, what is the point of having a specific image in every density folder? 考虑到图像会根据屏幕自动调整大小,在每个密度文件夹中都有特定图像有什么意义?

An image in every folder makes the app size much bigger and it takes of course much more time to prepare. 每个文件夹中的图像都会使应用程序变得更大,并且准备工作当然要花费更多时间。

What are the risks of not handling all the densities from xhdpi to lpdi? 不处理从xhdpi到lpdi的所有密度的风险是什么?

EDIT: Example below of an image I use as a pattern. 编辑:我下面的图像示例用作图案。 FYI, I use this code to multiply the pattern: 仅供参考,我使用以下代码将模式相乘:

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/butterfly" 
    android:tileMode="repeat" />

背景图案示例


One downside of your approach is that sometimes larger icons need more details than smaller icons do. 这种方法的一个缺点是,有时较大的图标比较小的图标需要更多的细节。 By using only one image for all densities you would also have the same amount of details in each case. 通过对所有密度仅使用一张图像,您在每种情况下的细节量也将相同。 Often, a lager and more detailed icon does not look good when scaled down (and vice-versa). 通常,更大且更详细的图标在缩小时看起来并不好(反之亦然)。

Nice article to read regarding this issue: http://www.pushing-pixels.org/2011/11/04/about-those-vector-icons.html 关于这个问题的好文章: http : //www.pushing-pixels.org/2011/11/04/about-those-vector-icons.html

The devices with ldpi / mdpi are essentially low profile devices which have severely constrained resources like memory. 具有ldpi / mdpi的设备本质上是薄型设备,其资源(如内存)受到严重限制。 If you are using large images for such devices, the issues you may face are: 如果您将大型图像用于此类设备,则可能面临的问题是:

  • An app that is slow to execute as large images have to be decompressed by the relatively less powerful CPUs 大型图像执行较慢的应用必须由功能相对较弱的CPU解压缩
  • OutOfMemory errors due to the images not fitting the heap size of these devices. 由于图像不适合这些设备的堆大小,导致内存不足错误。

Edit: This answer assumes that the OP understands the reason for Providing Alternate Bitmaps and is only interested in knowing the risks in not following the Best Practices . 编辑:此答案假设OP理解提供备用位图的原因,并且仅对了解不遵循最佳做法的风险感兴趣。

From here: http://developer.android.com/training/multiscreen/screendensities.html 从这里: http : //developer.android.com/training/multiscreen/screendensities.html

Since Android runs in devices with a wide variety of screen densities, you should always provide your bitmap resources tailored to each of the generalized density buckets: low, medium, high and extra-high density. 由于Android在具有多种屏幕密度的设备上运行,因此您应始终提供针对每个通用密度分区(低,中,高和超高密度)量身定制的位图资源。 This will help you achieve good graphical quality and performance on all screen densities. 这将帮助您在所有屏幕密度上获得良好的图形质量和性能。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用res文件夹的drawable-hdpi,drawable-mdpi,drawable-ldpi中存在的图像? - how to use images present in drawable-hdpi,drawable-mdpi,drawable-ldpi of res folder? 应用程序未从 ldpi mdpi hdpi 文件夹中获取图像 - App is not taking images from ldpi mdpi hdpi folder 'drawable'文件夹和'drawable-hdpi-ldpi-mdpi-xhdpi'文件夹之间有什么区别? - What's differences between 'drawable' folder and 'drawable-hdpi-ldpi-mdpi-xhdpi' folders? Drawable V21 vs V24 vs hdpi、mdpi、xhdpi 等自定义文件夹。 我应该将图像放在哪个文件夹中以支持多设备? - Drawable V21 vs V24 vs custom folders for hdpi,mdpi,xhdpi etc.. ? In which folder should I put my images for multi-device support? 避免多个可绘制集(hdpi / mdpi / ldpi) - Avoid Multiple Drawable Sets (hdpi/mdpi/ldpi) 可以从mdpi加载而不是hdpi中绘制 - Drawable from mdpi loading instead of hdpi 我应该在drawable和drawable-hdpi文件夹中保留图像吗? - Should I keep images in both drawable and drawable-hdpi folder? 使用drawable文件夹中的默认资源(MDPI大小)drawable-mdpi文件夹的重点是什么? - With default resources in the drawable folder (MDPI sized) what's the point of the drawable-mdpi folder? 我可以只提供一个可绘制文件夹,而不是4个(hdpi,ldpi,mdpi,xhpi) - Can i provide just one drawable folder instead of 4 (hdpi,ldpi,mdpi,xhpi) 如果图像相同,是否应该为所有可绘制文件夹(ldpi-mdpi-hdpi)创建调整大小的图像? - Should I create resized images for all drawable folders (ldpi-mdpi-hdpi) if the image is the same?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM