我尝试使用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相同的结果。
任何帮助都将不胜感激。
发布于 2017-04-18 10:23:48
这里的问题是,您传递给ObjectAnimator的值不是百分比,而是绝对值。
所以你必须计算视图的高度,然后把它传递给ObjectAnimator ie。
ObjectAnimator.ofFloat(filterLayout,"translationY",calcHeight,calcHeight * 0.1f);发布于 2019-05-29 17:45:14
我知道现在很晚了,但是,请检查下面的代码,看看是否适用于您的情况。我将您共享的XML代码作为参考。
ObjectAnimator.ofPropertyValuesHolder(
view,
PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, 100.0f, 10.0f));https://stackoverflow.com/questions/40182137
复制相似问题