我正在尝试使用 ObjectAnimator 来制作向上滑动的翻译动画,因为我们知道,如果我们像这样使用普通的翻译动画,onclicklistener 将无法工作,
<translate
android:duration="1000"
android:fromYDelta="100%"
android:toYDelta="10%" />
上面的 xml 代码工作正常,但正如我之前所说,onclicklistener 在动画之后不起作用。 我尝试了如下所示的 ObjectAnimator
ObjectAnimator mover = ObjectAnimator.ofFloat(filterLayout, "translationY", 1.0f, 0.1f);
mover.start();
但它不会给出与 translate xml 相同的结果。
如有任何帮助,我们将不胜感激。
最佳答案
这里的问题是您传递给 ObjectAnimator 的值不是百分比,而是绝对值。
因此您必须计算 View 的高度,然后将其传递给 ObjectAnimator 即。
ObjectAnimator.ofFloat(filterLayout,"translationY",calcHeight,calcHeight * 0.1f);
关于android - 使用 ObjectAnimator 向上滑动动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40182137/