Android 带深度的反弹动画

Android 带深度的反弹动画,android,android-animation,Android,Android Animation,我如何才能添加反弹动画,以查看哪些将下降和上升,但它应该只这样做一次 如果我将“反弹插值器”设置为y,则其在给定的持续时间内反弹 但我只想要一次,但它应该说5dp下降和上升到当前的看法 ObjectAnimator animator = ObjectAnimator.ofFloat(targetView, "translationY", 0, 50, 0); animator.setInterpolator(new BounceInterpolator()); anima

我如何才能添加反弹动画,以查看哪些将下降和上升,但它应该只这样做一次

如果我将“反弹插值器”设置为y,则其在给定的持续时间内反弹 但我只想要一次,但它应该说5dp下降和上升到当前的看法

    ObjectAnimator animator = ObjectAnimator.ofFloat(targetView, "translationY", 0, 50, 0);
    animator.setInterpolator(new BounceInterpolator());
    animator.setDuration(200);
    animator.start();

使用
超调器分离器

文件:

一种插值器,其中的变化向前抛出并超出 最后一个值返回

您可以使用构造函数通过
张力
参数调整超调张力:

OvershootInterpolator(float tension)
张力:超调量。当张力等于0.0f时,不存在 过冲和插值成为一个简单的减速 内插器

张力的默认值为
2.0f

使用
ViewPropertyAnimator
的示例:

targetView.animate()
    .translationY(50)
    .setInterpolator(new OvershootInterpolator())
    .setDuration(200);
使用ObjectAnimator:

ObjectAnimator animator = ObjectAnimator.ofFloat(targetView, "translationY", 0, 50); // pass only start and end values. 
    animator.setInterpolator(new OvershootInterpolator());
    animator.setDuration(200);
    animator.start();

和ObjectAnimator?是的
ObjectAnimator
ViewPropertyAnimator
。两者都应该有效。在相关说明中,您可以将
View.TRANSLATION\u Y
而不是
“translationY”
传递给
ObjectAnimator
,前者更好,因为后者涉及反射。或者使用
ViewPropertyAnimator
。在此之后,我将如何重置视图
translationY(0)
将其重置为原始位置。