简体   繁体   中英

Android. TranslateAnimation takes no effect

I am trying to create animation that moves an image.

Lets have a look at following (like image locations on screen):

  • 01 02
  • 03 04

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

But when I do 01 to 04 I will have no visual animation, and image takes immediate vertical position.

Could you please suggest what could be wrong?

Thanks.

Are you setting the duration and interpolator? This code works for me (was struggling with the same issue tonight):

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 queried in an activities constructor, so trying to transform based on those is going to give you a lot of 0->0 movement (ie: none) If you are animating based on element dimensions you may want to do some logging/Toasting to make sure you actually have a width/height at the point that you create the animation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM