Monday, 6 February 2023

How to `fitHeight` a drawable (VectorDrawable/BitmapDrawable) in XML resource

I am trying to fit a drawable (VectorDrawable/BitmapDrawable) that got a 1:1 aspect ratio on first frame of Android.

I tried the following attempt without success:

styles.xml

<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
    <item name="android:windowBackground">@drawable/launch_background</item>
</style>

launch_background.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@android:color/white" />
    <item android:drawable="@drawable/splashscreen" android:gravity="top|bottom"/>
</layer-list>

This does not maintain aspect ratio, same behavior as top|bottom|right|left as far as I can tell.

I desired this output:

Desired Output

Any ideas how to achieve this?



from How to `fitHeight` a drawable (VectorDrawable/BitmapDrawable) in XML resource

No comments:

Post a Comment