Reputation: 454
I have a problem with my animation. The idea is to move some imageviews to another imageviews positions using TranslateAnimation as you can see here:
the animation works fine, the problem comes when I want to continue executing the code just after animation ends (it's is supposed to be executed after that). I'm trying to ensure this using handler or onAnimationEnd but can't syncronize it fine.
Either the code takes place during the animation or it's executed after the animation.
-During the animation: It's a matter of milliseconds but enough noticeable that the ImageView it's shown one position ahead, after that little time ends it returns to the desired position, this happens because I'm changing the ImageView in the way it's shown in the Animation using setImageResource but if that change happens before the animation ends then we'll see the ImageView one position ahead as I said before and you can see in the following picture:
-After the animation: Well, the animation ends and some milliseconds after that the code it's executed, during that time the ImageView returns to the initial position, after that little time it goes to the desired position, here applies the same explanation from above because I'm using the same code, the difference is that the code it's executed after the animation:
In Handler I was using the same waiting time as the Animation duration and I had this problem (same with onAnimationEnd). So I tried different times in the Handler and the closest time to not notice this was the animation duration + 25 milliseconds (at least in my phone) but it fails sometimes and idk how it will work on different devices, surely that depends on chips processing, so it's not a solution.
Here it's a little part of the code using Handler:
AnimationsConfig(); //Configuring translate animations
anim.setDuration(500);
anim2.setDuration(500);
anim3.setDuration(500);
anim4.setDuration(500);
anim5.setDuration(500);
anim6.setDuration(500);
animation.startAnimation(anim);
animation2.startAnimation(anim2);
animation3.startAnimation(anim3);
animation4.startAnimation(anim4);
animation5.startAnimation(anim5);
animation6.startAnimation(anim6);
new Handler().postDelayed(new Runnable() {
public void run() {
DrawNewPositions(); //Changing imageviews resources according to the animation
}
}, 500L);
Alternatively used Animation.setFillAfter(true)
but with DrawNewPositions()
in the code leaves the ImageView one position ahead forever, not just millisecons then it's worse, if I remove DrawNewPositions()
the ImageView
will start from it first position forever.
I need a solution to solve this, those changes can't be noticeable in the user eyes and have to be enough smooth.
Thanks
Upvotes: 1
Views: 821
Reputation: 443
this way of animation don't move x,y but just make animation, so you have to change x,y for each object after the animation.
Upvotes: 0