Created
November 20, 2017 21:46
-
-
Save cacheleocode/7abb684d91d3f0015199dd441cd5415e to your computer and use it in GitHub Desktop.
Android - Loop Lottie animation with delay in between
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.domingl.lottietest; | |
import android.animation.Animator; | |
import android.animation.Animator.AnimatorListener; | |
import android.os.Handler; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import com.airbnb.lottie.LottieAnimationView; | |
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
// Lottie Animation | |
final LottieAnimationView animationViewRemote = (LottieAnimationView) findViewById(R.id.animation_view_remote); | |
animationViewRemote.setAnimation("remote.json"); | |
animationViewRemote.loop(false); | |
animationViewRemote.playAnimation(); | |
// handler | |
final Handler handler = new Handler(); | |
animationViewRemote.addAnimatorListener(new AnimatorListener() { | |
@Override | |
public void onAnimationStart(Animator animator) { | |
animationViewRemote.pauseAnimation(); | |
handler.postDelayed(new Runnable() { | |
@Override | |
public void run() { | |
// do something after 1.5s | |
animationViewRemote.playAnimation(); | |
} | |
}, 1500); | |
} | |
@Override | |
public void onAnimationEnd(Animator animator) { | |
handler.postDelayed(new Runnable() { | |
@Override | |
public void run() { | |
// do something after 1.5s | |
animationViewRemote.playAnimation(); | |
} | |
}, 1500); | |
} | |
@Override | |
public void onAnimationCancel(Animator animator) { | |
} | |
@Override | |
public void onAnimationRepeat(Animator animator) { | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment