2

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?

SwissCodeMen
  • 4,222
  • 8
  • 24
  • 34
Exprove
  • 1,301
  • 2
  • 18
  • 32

1 Answers1

1

Try using android:gravity="center|bottom|clip_vertical"

The only downside is that if there is not enough space, your image won't be fully shown, but it will be clipped, I couldn't find an way to do this directly from a drawable. But from the tests I did it works pretty well, and it doesn't clip that much of the image. You could play more with the gravity options.

Another way will be to just create an layout, where you will use an ImageView and set the scaleType to fitCenter.

Lukas
  • 812
  • 1
  • 14
  • 43