Android. TranslateAnimation has no effect

I am trying to create an animation that moves an image.

Lets take a look at the following (for example, screen images):

  • 01 02
  • 03 04

If I go from 01 to 02 , 03 to 04 , 01 > to 03 , 02 to 04 , TranslateAnimation works fine.

But when I do 01 to 04 I have no visual animation and the image will take an immediate vertical position.

Could you suggest what might be wrong?

Thank.

+2


source to share


1 answer


Do you specify duration and interpolator? This code works for me (struggling with the same problem today):

trans = new TranslateAnimation(0, 100, 0, 100);
trans.setDuration(250);
trans.setInterpolator(new AccelerateInterpolator(1.0f));
someView.startAnimation(trans);

      



Also, I found that most elements don't actually have a width or height when requested in the action constructor, so trying to transform based on those parameters will give you a lot of 0-> 0 motion (i.e.: none) If you animate based on dimensions element, you might want to do some writing / toasting to make sure you actually have a width / height at the point where you create the animation.

0


source







All Articles