java.lang.IllegalStateException: 无法为 X 创建层——当使用硬件层时 [英] java.lang.IllegalStateException: Unable to create layer for X -- when using hardware layers
问题描述
我在自定义视图上使用硬件层,以便在为其 Alpha 设置动画时获得更好的性能.在我的崩溃报告器上看到这次崩溃:
I'm using hardware layers on a custom view for better performance when animating its alpha. Seeing this crash on my crash reporter:
Fatal Exception: java.lang.IllegalStateException: Unable to create layer for X
at android.os.MessageQueue.nativePollOnce(MessageQueue.java)
at android.os.MessageQueue.next(MessageQueue.java:323)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5585)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
我目前的解决方法是等待这种情况发生,然后为设备不支持硬件层"存储一个布尔值,然后继续崩溃一次……然后下一次回退到更简单的动画.
My current workaround is waiting for this to happen, then storing a boolean for "device doesn't support hardware layers", and continuing with the crash that one time... then next time falling back to a simpler animation instead.
鉴于这是异步发生的,我无法真正尝试捕获.有没有人知道有什么方法可以预先检查操作是否成功,以便直接使用回退而不必在用户身上崩溃一次?
Given that this happens asynchronously, I can't really try-catch. Does anyone know of a way to check beforehand whether the operation would succeed, in order to use the fallback directly and not having to crash on the user even once?
谢谢!
推荐答案
看起来类似于 https://issuetracker.google.com/issues/118714995.看看这是否有帮助.
Looks similar to https://issuetracker.google.com/issues/118714995. See if this helps.
使用 View#forceHasOverlappingRendering(false) 设置您的父视图.
Setting your parent view with View#forceHasOverlappingRendering(false).
这篇关于java.lang.IllegalStateException: 无法为 X 创建层——当使用硬件层时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!