gpt4 book ai didi

android - AOS 4.x 动画崩溃问题

转载 作者:搜寻专家 更新时间:2023-11-01 08:59:35 28 4
gpt4 key购买 nike

我有一个窗口弹出类,它在 aos 2.x(如 2.2.2、2.3.5 等)中运行良好,但在 aos 4.x 中崩溃。导致崩溃的代码如下:

public void dismissPopup(){
if (!isVisible)
return;
isVisible = false;

final Animation animation = AnimationUtils.loadAnimation(activity, R.anim.popup_hide);
animation.setAnimationListener(new AnimationListener() {
public void onAnimationEnd(final Animation animation) {
// The animation has ended
popupWindow.dismiss();
}
public void onAnimationRepeat(final Animation animation) {}
public void onAnimationStart(final Animation animation) {}
});
popupView.startAnimation(animation);
}

所以为了让它在 aos 4.x 中工作,我必须注释所有的动画线,就像它有 2b 一样:

public void dismissPopup(){
if (!isVisible)
return;
isVisible = false;

popupWindow.dismiss();
}

这在 aos 4.1.x 中工作正常,但不提供动画。这里可能是什么问题? android 不应该提供任何向后兼容性吗?
崩溃日志

04-25 21:05:50.387: E/AndroidRuntime(8997): FATAL EXCEPTION: main
04-25 21:05:50.387: E/AndroidRuntime(8997): java.lang.NullPointerException
04-25 21:05:50.387: E/AndroidRuntime(8997): at android.view.ViewRootImpl.drawAccessibilityFocusedDrawableIfNeeded(ViewRootImpl.java:2301)
04-25 21:05:50.387: E/AndroidRuntime(8997): at android.view.ViewRootImpl.onHardwarePostDraw(ViewRootImpl.java:1931)
04-25 21:05:50.387: E/AndroidRuntime(8997): at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:1182)
04-25 21:05:50.387: E/AndroidRuntime(8997): at android.view.ViewRootImpl.draw(ViewRootImpl.java:2147)
04-25 21:05:50.387: E/AndroidRuntime(8997): at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2019)
04-25 21:05:50.387: E/AndroidRuntime(8997): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1830)
04-25 21:05:50.387: E/AndroidRuntime(8997): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:998)
04-25 21:05:50.387: E/AndroidRuntime(8997): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4212)
04-25 21:05:50.387: E/AndroidRuntime(8997): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:736)
04-25 21:05:50.387: E/AndroidRuntime(8997): at android.view.Choreographer.doCallbacks(Choreographer.java:566)
04-25 21:05:50.387: E/AndroidRuntime(8997): at android.view.Choreographer.doFrame(Choreographer.java:536)
04-25 21:05:50.387: E/AndroidRuntime(8997): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:722)
04-25 21:05:50.387: E/AndroidRuntime(8997): at android.os.Handler.handleCallback(Handler.java:615)
04-25 21:05:50.387: E/AndroidRuntime(8997): at android.os.Handler.dispatchMessage(Handler.java:92)
04-25 21:05:50.387: E/AndroidRuntime(8997): at android.os.Looper.loop(Looper.java:137)
04-25 21:05:50.387: E/AndroidRuntime(8997): at android.app.ActivityThread.main(ActivityThread.java:4745)
04-25 21:05:50.387: E/AndroidRuntime(8997): at java.lang.reflect.Method.invokeNative(Native Method)
04-25 21:05:50.387: E/AndroidRuntime(8997): at java.lang.reflect.Method.invoke(Method.java:511)
04-25 21:05:50.387: E/AndroidRuntime(8997): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
04-25 21:05:50.387: E/AndroidRuntime(8997): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
04-25 21:05:50.387: E/AndroidRuntime(8997): at dalvik.system.NativeStart.main(Native Method)

UPD:动画在 aos 4.0.3 中有效,但在 4.1.1 中崩溃

最佳答案

我发现它很愚蠢但解决方法是:

animation.setAnimationListener(new AnimationListener() {
public void onAnimationEnd(final Animation animation) {
// The animation has ended
new Handler().post(new Runnable() {
@Override
public void run() {
popupWindow.dismiss();
}
});
}
public void onAnimationRepeat(final Animation animation) {}
public void onAnimationStart(final Animation animation) {}
});

我什至无法想象为什么这有帮助,为什么在 4.1.1 中没有它就不能工作...

关于android - AOS 4.x 动画崩溃问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16221175/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com