【问题标题】:How to make TranslateAnimation update position while animating如何在制作动画时使 TranslateAnimation 更新位置
【发布时间】:2015-08-05 02:06:48
【问题描述】:

所以当我的TranslateAnimation 播放 10 秒动画时,它的位置实际上并没有更新。

它唯一更新的时间是动画结束时。

那么我怎样才能让TranslateAnimation 在动画时更新它的位置?

通过更新它的位置,我的意思是,如果我检查它的位置,IE;视图的上下左右坐标,如果它移动了,我应该得到一组不同的数字。

但在这种情况下,我得到了视图原始位置的位置,这不是我想要的。我想要它在动画期间移动的 View AS 的位置,但似乎没有办法做到这一点。

【问题讨论】:

  • 您的目标是什么 API?

标签: java android android-animation


【解决方案1】:

您是否尝试过使用ObjectAnimator?以下代码实际上会移动您的视图,而不仅仅是动画:

ObjectAnimator animation = ObjectAnimator.ofFloat(yourView, "translationX", 0.0f, yourHorizontalTranslationTarget);
ObjectAnimator animation = ObjectAnimator.ofFloat(yourView, "translationY", 0.0f, yourVerticalTranslationTarget);

请注意,yourHorizontalTranslationTargetyourVerticalTranslationTarget 是以像素为单位的绝对值,而不是百分比。

然后您可以将它们加入AnimationSet,这样它们就会同时被执行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-26
    • 2012-02-24
    • 1970-01-01
    • 2015-12-16
    • 2012-09-15
    • 2019-03-15
    • 2014-06-21
    相关资源
    最近更新 更多