如何在动画时使 TranslateAnimation 更新位置

How to make TranslateAnimation update position while animating

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

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

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

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

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

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

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

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

然后您可以将它们加入到 AnimationSet 中,以便它们同时执行。