Problem with AnimationSet in android

I am using AnimationSet to execute a TranslateAnimations sequence.

icon = (ImageView)findViewById(R.id.icon); AnimationSet animationSet = new AnimationSet(true); animationSet.setInterpolator(new AccelerateInterpolator()); TranslateAnimation slide1 = new TranslateAnimation(0, 50, 0, 100); slide1.setStartOffset(0); slide1.setDuration(800); animationSet.addAnimation(slide1); TranslateAnimation slide2 = new TranslateAnimation(50, 100, 100, -100); slide2.setStartOffset(1000); slide2.setDuration(800); animationSet.addAnimation(slide2); .... animationSet.setFillAfter(true); icon.startAnimation(animationSet); 

My problem is that the animation is very jerky. The first animation happens very abruptly, then the second begins. How can I make it smooth and even?

+4
source share
2 answers

create an xml file for animation and try

  AnimationSet animSet = new AnimationSet(false); Animation AnimFirst = AnimationUtils.loadAnimation(act, R.anim.first); Animation rAnimSecond = AnimationUtils.loadAnimation(act, R.anim.second); animSet.addAnimation(AnimFirst); animSet.addAnimation(AnimSecond); animSet.setInterpolator(new AccelerateDecelerateInterpolator()); icon.clearAnimation(); animSet.setFillAfter(true); icon.startAnimation(animSet); 

animFirst.xml

  <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromYDelta="100%" android:toXDelta="0" android:duration="2000" android:fillAfter="true" /> </set> 

u should change the value no matter if you want.

+5
source

Try using a longer animation duration (> = 1500).

0
source

Source: https://habr.com/ru/post/1344246/


All Articles