1

I have adaptive XML icon, built from 3 drawables.

<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
    <background>
        <layer-list>
            <item>
                <shape>
                    <solid android:color="#fff" />
                    <size android:width="108dp" android:height="108dp" />
                </shape>
            </item>
            <item android:drawable="@drawable/icon_abc"
                android:width="54dp"
                android:height="27dp"
                android:top="27dp"
                android:left="27dp" />
        </layer-list>
    </background>
    <foreground>
        <layer-list>
            <item
                android:width="108dp"
                android:height="56dp"
                android:drawable="@drawable/icon_foreground"
                android:top="56dp"
                />
            <item
                android:width="54dp"
                android:height="27dp"
                android:drawable="@drawable/icon_pluseq"
                android:left="27dp"
                android:top="56.5dp"
                />
        </layer-list>
    </foreground>
</adaptive-icon>

Below is a preview from Android Studio.

Android Studio Preview

But when I install my app on emulator (API v27), I see this:

Actual adaptive icon look

I've read answers to that question before writing this. In the linked question problem was in unappropriate size of icon, but my icon has size 108x108dp and inner foreground has size 72x72dp (as it is shown in the preview). In this case I see that icon is not centered at all.

UPD: In the Overview window icon displays properly:

Overview icon

UPD 2: If I use classic approach and provide two webp mipmaps for background and foreground like below, then icon displays as expected.

<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
    <background android:drawable="@mipmap/icon_xxhdpi_background" />
    <foreground android:drawable="@mipmap/icon_xxhdpi_foreground" />
</adaptive-icon>

But with that approach I can't implement xml drawable e.g. for scaling mipmaps for round version of icon. That means I'm forced to store 2 differend versions of webp icons (4 images) with total size of 10 KiB, that is 5 times bigger than 2 KiB of xml version.

UPD 3: Below is a comparison of output for xxhdpi and hdpi screens respectively

xxhdpi icon hdpi icon

As I can see, results are different. Maybe there's a sort of resolution issue, maybe in resource folders naming.

UPD 4: I've checked possible solution, suggested in comments.

Using bitmaps instead of drawable references makes no difference since final result is properly builded (as I can see in Overview window), but "desktop" version of icon is still displays improperly.

Seems like this is a system bug :(

RomanMitasov
  • 925
  • 9
  • 25
  • Your problem may be with the layer list. Take a look at the [documentation](https://developer.android.com/guide/topics/resources/drawable-resource#LayerList) especially the part about how items scale up to the view size and the use of bitmaps and gravity. – Cheticamp May 18 '20 at 15:19
  • @Cheticamp, I've just tried to check your theory and encountered a couple of more intresting problems. If I use `center` gravity just like in docs, then original images scaled inproperly. If I use `fill` gravity instead - the result is the same as above. I think I can try to change `dp` units to `px` and resize bitmaps... – RomanMitasov May 19 '20 at 14:11

1 Answers1

0

Just make a vector of your icon.

krissemicolon
  • 129
  • 12
  • Please provide more arguments and examples, I don't really understand, what should i do and how can it help. – RomanMitasov May 24 '20 at 17:08
  • Its easier that way. Just take the easy route. – krissemicolon May 24 '20 at 17:48
  • Easier way I introduced in the question. The classic way of making an icon - two images (vectors, png whatever). So, I know how to do "easier". But the whole point of my question - find more elegant solution. Your answer does'nt really answer anything, imho. – RomanMitasov May 24 '20 at 20:40
  • Ok if you want i will delete it. I just needed reputation to get out of my quetion ban. – krissemicolon May 25 '20 at 07:50