问题描述
我在我的应用程序启用硬件加速,但我已经禁用它,因为我有问题,中风帽和其他的东西我的意见之一。
I have hardware acceleration enabled in my app but I have disabled it for one of my views because I had problems with stroke caps and other things.
现在我收到了谷歌播放崩溃错误控制台该堆栈跟踪:
Now I'm getting this stack trace in the Google Play Crash Errors console:
java.lang.UnsupportedOperationException
at android.view.GLES20Canvas.clipPath(GLES20Canvas.java:287)
at com.myapp.MyCustomView.onDraw(SourceFile:288)
at android.view.View.draw(View.java:9310)
at android.view.View.getDisplayList(View.java:8773)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2298)
...
at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:609)
at android.view.ViewRoot.draw(ViewRoot.java:1634)
at android.view.ViewRoot.performTraversals(ViewRoot.java:1450)
at android.view.ViewRoot.handleMessage(ViewRoot.java:2094)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:132)
at android.app.ActivityThread.main(ActivityThread.java:4123)
...
我指定了安卓hardwareAccelerated =真正的
在AndroidManifest.xml中。但是,我专门禁用硬件加速在我的自定义视图的构造器:
I have specified android:hardwareAccelerated="true"
in AndroidManifest.xml. But I specifically disabled hardware acceleration in the constructor of my custom view:
public MyCustomView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// ... code omitted
// disable acceleration because Paint.setStrokeCap(Cap.ROUND) is not working otherwise
Compatibility.disableHardwareAcceleration(this);
}
通过兼容性是这样的:
public class Compatibility {
// View.setLayerType() was introduced in Honeycomb
private static Method setLayerTypeMethod = getMethod(View.class, "setLayerType", int.class,
Paint.class);
private static Method getMethod(Class<?> clazz, String name, Class<?>... parameterTypes) {
try {
return clazz.getMethod(name, parameterTypes);
}
catch (NoSuchMethodException e) {
return null;
}
}
private Compatibility() {
}
public static void disableHardwareAcceleration(View view) {
try {
if (setLayerTypeMethod != null) {
int layerType = 1; // View.LAYER_TYPE_SOFTWARE
setLayerTypeMethod.invoke(view, layerType, null);
}
}
catch (Exception ignored) {
}
}
}
不幸的是,崩溃的错误控制台没有透露有关Android操作系统版本或设备的信息。
Unfortunately the Crash Errors console does not reveal information about the Android OS version or device.
任何想法可能什么呢?
推荐答案
有一个已知问题,其中一个观点是仍然使用,即使LAYER_TYPE_SOFTWARE设置硬件加速绘制。详情这里
There is a know issue where a view is still drawn using hardware acceleration even if LAYER_TYPE_SOFTWARE was set. Details are here
作为一种解决办法,你可以做两件事
As a workaround you can do two things
- 使用Canvas.isHardwareAccelerated()跳过问题code。
- 在画有问题的东西,成位图,并与canvas.drawBitmap()得出这样到硬件加速的观点。
- use Canvas.isHardwareAccelerated() to skip the problematic code.
- draw the problematic stuff into a bitmap and and draw this with canvas.drawBitmap() onto the hardware accelerated view.
这篇关于UnsupportedOperationException异常的GLES20Canvas.clipPath硬件加速禁用视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!