我有一个自定义的AdapterView,它会覆盖drawChild以在画布动画期间剪切子视图。
这似乎可以在蜂窝状态下正常工作,但一旦加载到Android 4.0平板电脑上就死了。我怀疑这是因为Android 4.0默认启用硬件加速,我使用的一个或多个画布方法不支持我使用的特定设备上的硬件加速(Acer A100和ICS 4.0.3)
这是我的drawChild方法(来自我的NinjaMenu.java类):
@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
final int top = child.getTop();
final int left = child.getLeft();
Bitmap bitmap = child.getDrawingCache();
if (bitmap == null) {
child.setDrawingCacheEnabled(true);
child.buildDrawingCache();
bitmap = child.getDrawingCache();
}
if (mCutPath != null) {
// clip child views so that they partially show
// as menu is expanded
canvas.clipPath(mCutPath);
canvas.drawBitmap(bitmap, left, top, null);
}
return false;
}
mCutPath是在代码中其他地方创建的Path对象(对此问题不重要)。
以下是AdapterView尝试绘制子项时发生的异常:
FATAL EXCEPTION: main
java.lang.UnsupportedOperationException
at android.view.GLES20Canvas.clipPath(GLES20Canvas.java:408)
at com.phunware.funimation.android.views.NinjaMenu.drawChild(NinjaMenu.java:529)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
at android.view.View.draw(View.java:10986)
at android.view.View.getDisplayList(View.java:10422)
at android.view.ViewGroup.drawChild(ViewGroup.java:2850)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
at android.view.View.getDisplayList(View.java:10420)
at android.view.ViewGroup.drawChild(ViewGroup.java:2850)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
at android.view.View.draw(View.java:10986)
at android.widget.FrameLayout.draw(FrameLayout.java:450)
at android.view.View.getDisplayList(View.java:10422)
at android.view.ViewGroup.drawChild(ViewGroup.java:2850)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
at android.view.View.getDisplayList(View.java:10420)
at android.view.ViewGroup.drawChild(ViewGroup.java:2850)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
at android.view.View.getDisplayList(View.java:10420)
at android.view.ViewGroup.drawChild(ViewGroup.java:2850)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
at android.view.View.getDisplayList(View.java:10420)
at android.view.ViewGroup.drawChild(ViewGroup.java:2850)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
at android.view.View.draw(View.java:10986)
at android.widget.FrameLayout.draw(FrameLayout.java:450)
at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2152)
at android.view.View.getDisplayList(View.java:10422)
at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:852)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:1910)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1634)
at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
除了完全禁用硬件加速之外,有没有办法检查给定的画布功能是否支持硬件加速,以及它是否不关闭它?
答案 0 :(得分:3)
坏消息:不,没有办法以编程方式检查给定的功能是否支持硬件加速。
好消息:你不是第一个碰到这个问题的人,而且有问题的功能(以及许多关于硬件加速的其他好处)都有很好的记录here:
请注意,该文档还列出了一些具有不同行为的函数。
一个可靠的解决方法是识别代码中有问题的操作,然后将它们绘制到位图中,然后将位图blit到加速画布。