Lottie-android: Lottie Animation Drawable Renders Incorrectly Inside a Floating Action Button on Android 5

Created on 11 Apr 2019  路  6Comments  路  Source: airbnb/lottie-android

loading_animation.zip

I'm trying to set a **LottieDrawable** as _image drawable_ for a FloatingActionButton. The problem comes when I try to run the code on an Android 5 device: the animation is not centered within the button as it is in Android >= 6. Somehow it is losing padding or margin. Anyone has an answer for this problem or maybe an workaround?

val lottieDrawable = LottieDrawable()

LottieCompositionFactory.fromRawRes(context, R.raw.loading_anim).addListener { lottieComposition ->
     lottieDrawable.composition = lottieComposition
     lottieDrawable.scale = 0.5F
     lottieDrawable.repeatCount = LottieDrawable.INFINITE
     lottieDrawable.playAnimation()
}

floatingActionButton.setImageDrawable(lottieDrawable)

Expected output (works correctly on Android 6,7,8,9,Q):
Expected_Result

Actual output (Android 5):
Actual_result_os5

All 6 comments

@gpeal any ideas on this, please?

@LucianIacob I haven't seen this before so I'll have to do some debugging. Feel free to do some as well.

@LucianIacob @gpeal Is this still open? Can I work on this?

@MonikaJethani You are welcome to take a look

have you set fab size in xml ? maybe you can try

android:scaleType="centerInside"
app:fabCustomSize="50dp"

instead of set layout_width and layout_height

@LucianIacob it's likely a bug on FloatingActionButton but if you set the animation _after_ it is laid out, it works.

Was this page helpful?
0 / 5 - 0 ratings