I'm trying to create a drawable painted by color with centered icon. I tried to create layer-list but it scales icon to match drawable size:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<solid android:color="@color/colorImageHolder"/>
</shape>
</item>
<item android:drawable="@drawable/no_photo" android:gravity="center">
</item>
</layer-list>
This is a real device picture:
I want it to look like this:
Is there any way to disable icon scaling ?
UPDATE: My ImageView
has scaleType="centerCrop"
and I think this is a root of problem :( I tried to place no_photo drawable as background but it scales again.
Try this
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<solid android:color="@color/colorImageHolder"/>
</shape>
</item>
<item android:drawable="@drawable/no_photo"
android:bottom="20dp"
android:left="20dp"
android:right="20dp"
android:top="20dp"
>
</item>
</layer-list>
Note: This solution only work with square or oval view, not rectangle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With