Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to use LottieDrawable: animation doesn't start #37

Closed
BoD opened this issue Feb 2, 2017 · 7 comments
Closed

Trying to use LottieDrawable: animation doesn't start #37

BoD opened this issue Feb 2, 2017 · 7 comments
Milestone

Comments

@BoD
Copy link

BoD commented Feb 2, 2017

Hi!
I just tried Lottie and I could make LottieAnimationView work with no problems.

However, I cannot make LottieDrawable work, and I wonder what I am doing wrong.

Here is what I do:

        LottieDrawable lottieDrawable = new LottieDrawable();
        mMainBinding.imgLottie.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        mMainBinding.imgLottie.setImageDrawable(lottieDrawable);
        LottieComposition.fromAssetFileName(this, "TwitterHeart.json", (composition) -> {
            lottieDrawable.setComposition(composition);
            lottieDrawable.loop(true);
            lottieDrawable.playAnimation();
        });

The result is I only see the first frame - the animation doesn't start.
I looked at the source of LottieAnimationView to compare, and didn't see any major difference.
Any idea?

@gpeal
Copy link
Collaborator

gpeal commented Feb 2, 2017

If you can attach a sample file, I'll investigate.

@BoD
Copy link
Author

BoD commented Feb 2, 2017

Here is a small project demonstrating the problem:
LottieTest.zip

@gpeal
Copy link
Collaborator

gpeal commented Feb 2, 2017

Thanks for the report. I have a fix up #49 and will release 1.0.1 soon.

@BoD
Copy link
Author

BoD commented Feb 2, 2017

👍

@gpeal gpeal closed this as completed in #49 Feb 2, 2017
@gpeal gpeal added this to the 1.0.1 milestone Feb 2, 2017
@gpeal
Copy link
Collaborator

gpeal commented Feb 2, 2017

@BoD Can you try again with Lottie 1.0.1? I just released it so it may take a few hours to propagate through maven.

@BoD
Copy link
Author

BoD commented Feb 3, 2017

I just tried, and I confirm it now works :)

@erleizh
Copy link

erleizh commented Feb 4, 2020

class LottieView @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {

    private var mLottieDrawable: LottieDrawable = LottieDrawable()

    init {
        mLottieDrawable.setImagesAssetsFolder("lottie/vip/images")
        mLottieDrawable.repeatCount = LottieDrawable.INFINITE
        mLottieDrawable.callback = this
        mLottieDrawable.repeatMode = LottieDrawable.RESTART
        LottieCompositionFactory.fromAsset(context.applicationContext, "lottie/vip/vip.json").addListener { result ->
            mLottieDrawable.composition = result
            mLottieDrawable.setBounds(0, 0, 100, 100)
        }
    }


    override fun onAttachedToWindow() {
        super.onAttachedToWindow()
        mLottieDrawable.start()
    }

    override fun onDetachedFromWindow() {
        super.onDetachedFromWindow()
        mLottieDrawable.stop()
    }

    override fun verifyDrawable(who: Drawable): Boolean {
        return who == mLottieDrawable || super.verifyDrawable(who)
    }

    override fun onDraw(canvas: Canvas) {
        mLottieDrawable.draw(canvas)
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants