android - Android 4.4 上 AnimatorSet.start 中的 NullPointerException

标签 android animation android-animation

我正在尝试使用 ObjectAnimator 和 AnimatorSet 启动动画。该代码在版本 >= Android 5.0 上运行良好,但在 Kitkat 4.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)

这是代码 fragment :

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();
    }

最佳答案

解决了! 以某种方式,Target View bottomContentControllers 符合:

ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(bottomContentControllers, "alpha", 1f, 0f);

在代码中的某个时刻被 Nullified。确保它永远不会得到 Null 并添加 Null 检查以使其工作。

关于android - Android 4.4 上 AnimatorSet.start 中的 NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54042702/

相关文章:

android - 在 RecyclerView 项目中处置

android - 在 Android 上保持应用程序状态

android - ViewAnimator 使用旋转动画在 View 之间转换

android - 加密字符串

android - Galaxy Ace (GT-S5830B) 上的 NoSuchMethodError

ios - 添加带有向上动画的部分/行

iphone - 代码 iPhone 图像绘制线条

ios - 使用自动布局时*仅一个*动画 block (UILabel) 的问题

android - 在 Android 中上下滑动更改布局

android动画将圆形图像向各个方向扩展