gpt4 book ai didi

android - 应用程序背景资源路径的最佳方式

转载 作者:行者123 更新时间:2023-11-30 00:36:22 25 4
gpt4 key购买 nike

我有多个高分辨率背景,需要按比例缩小以适应较低的屏幕,正如 Stack Overflow 中所建议的,我已将它们放在 drawable 文件夹中。我不知道它是否正确,所以我尝试测试。

我有 OutOfMemory 异常,因此我不得不将它们移动到 drawable-nodpi,它运行良好,没有任何异常,但我不知道这是不是在 Android 中使用它的正确方法。

对此有什么建议吗?有人说我需要为每个屏幕制作背景,例如 xxhdpixhdpi,但我想在最高屏幕制作背景,并更好地缩小它?

最佳答案

I've put them in drawable folder. I don't know if its correct or not, so i tried to test.

如果您将可绘制对象放入 drawable 文件夹中,Android 将针对所有屏幕尺寸使用该可绘制对象,缩放可绘制对象以反射(reflect)设备的密度(例如 xhdpi 设备会将图像放大 2 倍)。

I had the OutOfMemory exception, therefore i had to move them to drawable-nodpi, it worked well without any exception, but i don't know if this is the correct way to use it in Android.

-nodpi 文件夹中的可绘制对象根本不会缩放。如果你想要缩放,那不是你想要的。

but i thought making a background in the highest screen, and scale it down better?

如果您只在 APK 中包含最高分辨率的图像,那么 Android 必须在您使用时将整个图像加载到内存中。如果您在 100x100 屏幕上显示 500x500 图像,Android 将需要将整个 500x500 图像加载到内存中。

屏幕较小的设备往往内存较少,因此这很可能导致 OutOfMemoryException

从设计的角度来看,您也无法控制缩小图像的外观。根据您的用例,这可能没问题。

Any suggestions for this

执行此操作的正确方法是预先缩放您的可绘制对象并将它们放置在适当的可绘制对象文件夹中。 1x 资源进入 drawable-mdpi,缩放到 1.5x 的资源进入 drawable-hdpi,等等。然后 Android 将只为设备屏幕加载正确大小的资源尺寸。

关于android - 应用程序背景资源路径的最佳方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43353693/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com