Updated 6 March 2021
In this blog, We implement, use and handling events, As we know that, Lottie is an animation Library that is used in Android, IOS, and React-Native applications.
In the previous blog, we learn about what is Lottie, its various functions, where we use? and it’s alternatives. https://mobikul.com/lottie-library-for-animation/
Now we implement Lottie-Library animations in our application and interact with them.
1 |
PorterDuffColorFilter colorFilter = new PorterDuffColorFilter(Color.GREEN, PorterDuff.Mode.LIGHTEN); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_color_filter); // use for color filter colorFilter = new PorterDuffColorFilter(Color.GREEN, PorterDuff.Mode.LIGHTEN); normalAnimation = (LottieAnimationView) findViewById(R.id.normal_animation); colorAnimation = (LottieAnimationView) findViewById(R.id.color_animation); LottieComposition.Factory.fromAssetFileName(this, "data.json", new OnCompositionLoadedListener() { @Override public void onCompositionLoaded(LottieComposition composition) { setComposition(composition); } }) ; } public void setComposition(LottieComposition composition) { normalAnimation.setComposition(composition); normalAnimation.loop(true); normalAnimation.playAnimation(); // change color colorAnimation.setComposition(composition); colorAnimation.addColorFilter(colorFilter); colorAnimation.loop(true); colorAnimation.playAnimation(); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_scalling); originalAnimation = (LottieAnimationView) findViewById(R.id.original_animation); scaleAnimation = (LottieAnimationView) findViewById(R.id.scalling_animation); originalAnimation.playAnimation(); LottieComposition.Factory.fromAssetFileName(this, "Belo Foggy.json", new OnCompositionLoadedListener() { @Override public void onCompositionLoaded(LottieComposition composition) { scaleAnimation.setComposition(composition); scaleAnimation.setScale(0.8f); scaleAnimation.playAnimation(); } }); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_event_listener); eventAnimation = (LottieAnimationView) findViewById(R.id.animation_view2); seekBar = (SeekBar) findViewById(R.id.seek_bar); LottieComposition.Factory.fromAssetFileName(this, "Spider Loader.json", new OnCompositionLoadedListener() { @Override public void onCompositionLoaded(LottieComposition composition) { seekBar.setProgress(0); eventAnimation.setComposition(composition); eventAnimation.loop(true); eventAnimation.playAnimation(); } }); seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (!eventAnimation.isAnimating()) { eventAnimation.setScale(0.1f); eventAnimation.setProgress(progress / 100f); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); eventAnimation.addAnimatorUpdateListener( new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { seekBar.setProgress((int) (animation.getAnimatedFraction() * 100)); } }); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_image_support); animationView = (LottieAnimationView) findViewById(R.id.animation_view_img); animationView.setAnimation("WeAccept.json"); animationView.setImageAssetsFolder("Images/WeAccept"); animationView.loop(true); submit = (LottieAnimationView) findViewById(R.id.submit_bt); submit.setAnimation("data.json"); submit.setImageAssetsFolder("images"); submit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { submit.setClickable(false); submit.playAnimation(); animationView.playAnimation(); findViewById(R.id.submit_text).setVisibility(View.GONE); animationView.setScale( animationView.getScale()/2.5f); } }); submit.addAnimatorUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { Log.d("Ashwini", "onAnimationUpdate: " + animation.getAnimatedFraction()); // use following code for set its progress between 0.15 to 0.25 if(submit.isAnimating() && animation.getAnimatedFraction() > 0.25){ submit.cancelAnimation(); submit.setProgress(0.15f); submit.playAnimation(); } } }); } |
Performance and Memory:-
Reference : https://github.com/airbnb/lottie-android#image-support
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
1 comments