简体   繁体   中英

Android drawble-xhdpi, drawable-xxhdpi, drawable-xxxhdpi subfolders inside DRAWABLE-V21 also for DRAWABLE-V23?

I know it is not possible to add subfolders inside drawable-v21. But how would I accomplish android to take different sizes of resources inside drawable-v21. For example for: drawable-xhdpi, drawable-xxhdpi, drawable-xxxhdpi.

I need this behaviour - (ic.png should be the same image with different pixel sizes)

  • drawable-v21

    • drawable-xhdpi

      ic.png

    • drawable-xxhdpi

      ic.png

    • drawable-xxxhdpi

      ic.png

  • drawable-v23

    • drawable-xhdpi

      ic.png

    • drawable-xxhdpi

      ic.png

    • drawable-xxxhdpi

      ic.png

How can I accomplish this?

Resource qualifiers can be used in combination with each other (though there is a specific order that must be followed when combining them). All qualifiers and their precedence order are listed here: https://developer.android.com/guide/topics/resources/providing-resources#AlternativeResources

You could, therefore, use a directory structure like this:

res/
    drawable-xhdpi-v21/
        ic.png
    drawable-xhdpi-v24/
        ic.png
    drawable-xxhdpi-v21/
        ic.png
    drawable-xxhdpi-v24/
        ic.png

Your own answer, however, implies that there is no difference between the ic.png file used for v21 and v24 . In this case, there's no need to specify the version at all:

res/
    drawable-xhdpi/
        ic.png
    drawable-xxhdpi/
        ic.png

UPDATE:

I realized I can solve my problem this way:

  • drawable

    • ic_vector.xml
    • ic.png (1.0x)
  • drawable-v21

    • outterDrawable.xml
  • drawable-v23

    • outterDrawable.xml
  • drawable-xhdpi

    • ic.png (1.0x)
  • drawable-xxhdpi

    • ic.png (2.0x)
  • drawable-xxxhdpi

    • ic.png (3.0x)

Where outterDrawable (drawable-v21) looks like this:

<?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>

Where outterDrawable (drawable-v23) looks like this:

<?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>

Let me know is there is a different solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM