cuốn sách gpt4 ai đã làm

android - Android 4.4 上 AnimatorSet.start 中的 NullPointerException

In lại Tác giả: Walker 123 更新时间:2023-11-29 02:23:02 29 4
mua khóa gpt4 Nike

我正在尝试使用 ObjectAnimator 和 AnimatorSet 启动动画。该代码在版本 >= Android 5.0 上运行良好,但在 Kitkat 4.4 上抛出 NullPointerException

 Caused by: java.lang.NullPointerException
Tại
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();
}

câu trả lời hay nhất

解决了!以某种方式,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/

29 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress