LottieAnimation未在Fragment中运行 [英] LottieAnimation not running inside Fragment

查看:70
本文介绍了LottieAnimation未在Fragment中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个明星动画来给评分,我在片段中创建了三个这样的LottieAnimationViews,以实现可重用性.当我从Fragment的 onCreate()方法中运行它时,LottieAnimation甚至没有启动(我正在使用支持Fragments).如果动画在 Activity (而不是片段)中,则使用完全相同的代码来运行动画.这是我的代码...

I have a star animation for giving rating and I created three of such LottieAnimationViews inside my fragment for the purpose of reuse-ability. The LottieAnimation doesn't even start when I run it from inside the onCreate() method of my Fragment (I am using support Fragments). The exact same code runs the animation if it is inside an Activity instead of a fragment. Here's my code...

    mLottieStarView1 = findViewById(R.id.rating_lottie_star_1);  //LottieView
    starLayout1 = findViewById(R.id.rating_star_layout_1); //Enclosing LinearLayout
    mValueAnimator1 = ValueAnimator.ofFloat(0f, 1f).setDuration(1500);

    //Create animation update methods
    mValueAnimator1.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {  //Star 1
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            mLottieStarView1.setProgress((Float) valueAnimator.getAnimatedValue());
        }
    });

    //Set listener on enclosing layout to run animation on touch
    starLayout1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mLottieStarView2.setProgress(0f);
            mLottieStarView3.setProgress(0f);
            mValueAnimator1.start();
        }
    });

推荐答案

确保将图像视图设置为 isClickable = true isFocusable = true 在xml中.

Make sure you set the image View to isClickable = true and isFocusable = true in xml.

使用 lottieView.playAnimation(); 方法启动抽奖动画,然后单击取消尝试

Start the lottie animation using the lottieView.playAnimation(); method and for the unclick try this

if(lottieTest.getFrame() == lottieTest.getMaxFrame()) {
   lottieTest.setFrame(1);
}

这篇关于LottieAnimation未在Fragment中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆