我正在尝试使用ObjectAnimator和AnimatorSet来启动动画。该代码在>= Android5.0版本上运行良好,但在Kitkat4.4上抛出了NullPointerException
Caused by: java.lang.NullPointerException
at
android.animation.PropertyValuesHolder.setupSetterAndGetter(PropertyValuesHolder.java:505)
at android.animation.ObjectAnimator.initAnimation(ObjectAnimator.java:487)
at android.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:517)
at android.animation.ValueAnimator.start(ValueAnimator.java:936)
at android.animation.ValueAnimator.start(ValueAnimator.java:946)
at android.animation.ObjectAnimator.start(ObjectAnimator.java:465)
at android.animation.AnimatorSet.start(AnimatorSet.java:563)
以下是代码片段:
public void playAnimation(Button doneButton, AnimatorEndListener endListener) {
long animDuration = 880;
ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(bottomContentControllers, "alpha", 1f, 0f);
float value = (float)(0 - doneButton.getHeight() - doneButton.getTop());
final ObjectAnimator slideUpDoneButton = ObjectAnimator.ofFloat(doneButton, "translationY",0f, value);
final AnimatorSet animSet = new AnimatorSet();
alphaAnimator.setDuration(animDuration);
slideUpDoneButton.setDuration(animDuration);
animSet.playTogether(alphaAnimator, slideUpDoneButton);
if(endListener != null) {
animSet.addListener(endListener);
}
animSet.start();
}
发布于 2019-01-08 03:00:55
解决了!不知何故,目标视图的bottomContentControllers排成一行:
ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(bottomContentControllers, "alpha", 1f, 0f);
在代码中的某个点被作废了。确保它永远不会得到Null,并添加了Null检查以使其工作。
https://stackoverflow.com/questions/54042702
复制相似问题