我知道不可能在draable-v21中添加子文件夹。但是,我将如何实现android,以便在可绘制的v21中占用不同大小的资源。例如:drawable xhdpi,drawable xhdpi,drawable xxhdpi。
我需要这种行为- (ic.png应该是具有不同像素大小的相同图像)
- drawable-xhdpiic.png
- drawable-xxhdpiic.png
- drawable-xxxhdpiic.png
- drawable-xhdpiic.png
- drawable-xxhdpiic.png
- drawable-xxxhdpiic.png
我怎样才能做到这一点?
发布于 2021-03-04 19:35:42
资源限定符可以相互结合使用(尽管在组合它们时必须遵循特定的顺序)。所有限定符及其优先顺序都在这里列出:https://developer.android.com/guide/topics/resources/providing-resources#AlternativeResources
因此,您可以使用这样的目录结构:
res/
drawable-xhdpi-v21/
ic.png
drawable-xhdpi-v24/
ic.png
drawable-xxhdpi-v21/
ic.png
drawable-xxhdpi-v24/
ic.png但是,您自己的答案意味着用于v21和v24的v21文件之间没有区别。在这种情况下,根本不需要指定版本:
res/
drawable-xhdpi/
ic.png
drawable-xxhdpi/
ic.png发布于 2021-03-04 18:30:34
更新:
我意识到我可以这样解决我的问题:
- ic\_vector.xml
- ic.png (1.0x)- outterDrawable.xml- outterDrawable.xml- ic.png (1.0x)- ic.png (2.0x)- ic.png (3.0x)其中,outterDrawable (draable-v21)如下所示:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<bitmap android:src="@drawable/ic" android:gravity="center" />
</item>
</layer-list>其中,outterDrawable (draable-v23)如下所示:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:src="@drawable/ic_vector" android:gravity="center"/>
</layer-list>让我知道有一个不同的解决方案。
https://stackoverflow.com/questions/66480563
复制相似问题