You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Lottie动画实现安卓启动页,播放完成后如何跳转其他Activity

Lottie启动页动画完成后跳转Activity实现方案

方式1:监听位移动画结束后跳转(适配你当前代码逻辑)

你当前代码中所有控件的位移动画统一延迟4000ms启动,执行时长1000ms,只需要给任意一个动画添加结束监听器,在动画结束时执行跳转逻辑即可,修改后的完整代码如下:

public class Splash extends AppCompatActivity {

    ImageView logo,splashImg;
    LottieAnimationView lottieAnimationView;
    TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_splash);

        logo = findViewById(R.id.logo);
        splashImg = findViewById(R.id.img);
        textView = findViewById(R.id.Motto);
        lottieAnimationView = findViewById(R.id.lottie);

        splashImg.animate().translationY(-2800).setDuration(1000).setStartDelay(4000);
        logo.animate().translationY(1850).setDuration(1000).setStartDelay(4000);
        textView.animate().translationY(1800).setDuration(1000).setStartDelay(4000);
        // 给Lottie的位移动画添加结束监听
        lottieAnimationView.animate().translationY(1800).setDuration(1000).setStartDelay(4000)
                .setListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {}

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        // 动画结束后跳转,将TargetActivity替换为你要跳转的Activity类名
                        if (!isFinishing()) {
                            Intent intent = new Intent(Splash.this, TargetActivity.class);
                            startActivity(intent);
                            finish();
                        }
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {}

                    @Override
                    public void onAnimationRepeat(Animator animation) {}
                });
    }
}

方式2:监听Lottie动画本身播放完成后跳转

如果你不需要等待后续的位移动画,希望Lottie自带的动画播放完成后就执行跳转,可以直接给Lottie控件添加动画监听器:

lottieAnimationView.addAnimatorListener(new Animator.AnimatorListener() {
    @Override
    public void onAnimationStart(Animator animation) {}

    @Override
    public void onAnimationEnd(Animator animation) {
        // 此处执行跳转逻辑,和上述方式1的跳转代码一致
        if (!isFinishing()) {
            Intent intent = new Intent(Splash.this, TargetActivity.class);
            startActivity(intent);
            finish();
        }
    }

    @Override
    public void onAnimationCancel(Animator animation) {}

    @Override
    public void onAnimationRepeat(Animator animation) {}
});

注意事项

  • 跳转完成后务必调用finish()关闭当前Splash页面,避免用户按返回键回到启动页
  • 跳转前添加isFinishing()判断,可以避免页面已经被销毁时触发跳转抛出异常
  • 如果你给Lottie设置了循环播放,跳转前需要先调用lottieAnimationView.cancelAnimation()停止动画

内容的提问来源于stack exchange,提问作者Prajesh Kayastha

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.30 04:06:03