简体   繁体   English

安卓 TranslateAnimation无效

[英]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 01 02
  • 03 04 03 04

If I move from 01 to 02 , 03 to 04 , 01 to 03 , 02 to 04 , TranslateAnimation works fine. 如果我从0102,0304,0103,0204移动,TranslateAnimation工作正常。

But when I do 01 to 04 I will have no visual animation, and image takes immediate vertical position. 但是当我从0104进行操作时,我将没有视觉动画,并且图像会立即占据垂直位置。

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. 另外,我发现在活动构造函数中查询时,大多数元素实际上没有宽度或高度,因此尝试根据这些元素进行变换将为您提供大量0-> 0的运动(即:无)。根据元素尺寸设置动画,您可能需要进行一些记录/烘烤,以确保在创建动画时实际具有宽度/高度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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