I.Step
I.Step

Reputation: 779

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)

How can I accomplish this?

Upvotes: 0

Views: 292

Answers (2)

I.Step
I.Step

Reputation: 779

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.

Upvotes: 0

Ben P.
Ben P.

Reputation: 54204

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

Upvotes: 1

Related Questions