对于动画,我必须聆听 ViewPropertyAnimator 的每一步。我将 AnimatorUpdateListener
与 setUpdateListener
结合使用。
来源:http://developer.android.com/reference/android/view/ViewPropertyAnimator.html
我如何使用它的例子:
image.animate().translationY(transY).setDuration(duration).setUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
// do my things
}
});
现在我正在将一个对象从 A 移动到 B,并且必须在移动时检测
一些东西。现在 setUpdateListener 对此很有帮助,使用这段代码一切正常。但它需要 api 级别 19。我真的想为这个项目使用 api 级别 14。 setUpdateListener
有替代方案吗?
ViewPropertyAnimator.setUpdateListener
Call requires api level 19 (current min is 14)
最佳答案
下面是对 Zsolt 的答案的改进,其中一个地方的监听器代码和 API 版本的代码级检查:
ValueAnimator.AnimatorUpdateListener updateListener = new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
// do my things
}
};
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
image.animate()
.translationY(transY)
.setDuration(duration)
.setUpdateListener(updateListener);
} else {
ObjectAnimator oa = ObjectAnimator.ofFloat(image, View.TRANSLATION_Y, transY)
.setDuration(duration);
oa.addUpdateListener(updateListener);
oa.start();
}
关于android - 在低于 19 的 api 级别上使用 setUpdateListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27271495/