使用Canvas clipPath时,我收到了UnsupportedOperationException。
这是在HTC Sensation XE(4.0.3)上发生的。 它在其他4.0.3设备上完美运行。
这是代码:
@Override
protected void dispatchDraw(Canvas canvas) {
canvas.save();
canvas.clipPath(this._mClip);
super.dispatchDraw(canvas);
canvas.restore();
}
使用以下堆栈的“clipPath”失败:
11-06 12:05:53.650: E/AndroidRuntime(25021): FATAL EXCEPTION: main
11-06 12:05:53.650: E/AndroidRuntime(25021): java.lang.UnsupportedOperationException
11-06 12:05:53.650: E/AndroidRuntime(25021): at android.view.GLES20Canvas.clipPath(GLES20Canvas.java)
11-06 12:05:53.650: E/AndroidRuntime(25021): at com.applicat.meuchedet.views.RoundedListView.dispatchDraw(RoundedListView.java:76)
11-06 12:05:53.650: E/AndroidRuntime(25021): at android.view.View.draw(View.java)
11-06 12:05:53.650: E/AndroidRuntime(25021): at android.widget.AbsListView.draw(AbsListView.java)
11-06 12:05:53.650: E/AndroidRuntime(25021): at android.widget.ListView.draw(ListView.java)
11-06 12:05:53.650: E/AndroidRuntime(25021): at android.view.View.getDisplayList(View.java)
11-06 12:05:53.650: E/AndroidRuntime(25021): at android.view.ViewGroup.drawChild(ViewGroup.java)
11-06 12:05:53.650: E/AndroidRuntime(25021): at android.view.ViewGroup.dispatchDraw(ViewGroup.java)
11-06 12:05:53.650: E/AndroidRuntime(25021): at android.view.View.getDisplayList(View.java)
11-06 12:05:53.650: E/AndroidRuntime(25021): at android.view.ViewGroup.drawChild(ViewGroup.java)
11-06 12:05:53.650: E/AndroidRuntime(25021): at android.view.ViewGroup.dispatchDraw(ViewGroup.java)
11-06 12:05:53.650: E/AndroidRuntime(25021): at android.view.View.draw(View.java)
11-06 12:05:53.650: E/AndroidRuntime(25021): at android.view.View.getDisplayList(View.java)
11-06 12:05:53.650: E/AndroidRuntime(25021): at android.view.ViewGroup.drawChild(ViewGroup.java)
11-06 12:05:53.650: E/AndroidRuntime(25021): at android.view.ViewGroup.dispatchDraw(ViewGroup.java)
11-06 12:05:53.650: E/AndroidRuntime(25021): at android.view.View.getDisplayList(View.java)
11-06 12:05:53.650: E/AndroidRuntime(25021): at android.view.ViewGroup.drawChild(ViewGroup.java)
11-06 12:05:53.650: E/AndroidRuntime(25021): at android.view.ViewGroup.dispatchDraw(ViewGroup.java)
11-06 12:05:53.650: E/AndroidRuntime(25021): at android.view.View.getDisplayList(View.java)
11-06 12:05:53.650: E/AndroidRuntime(25021): at android.view.ViewGroup.drawChild(ViewGroup.java)
11-06 12:05:53.650: E/AndroidRuntime(25021): at android.view.ViewGroup.dispatchDraw(ViewGroup.java)
11-06 12:05:53.650: E/AndroidRuntime(25021): at android.view.View.draw(View.java)
11-06 12:05:53.650: E/AndroidRuntime(25021): at android.widget.FrameLayout.draw(FrameLayout.java)
11-06 12:05:53.650: E/AndroidRuntime(25021): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java)
11-06 12:05:53.650: E/AndroidRuntime(25021): at android.view.View.getDisplayList(View.java)
11-06 12:05:53.650: E/AndroidRuntime(25021): at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java)
11-06 12:05:53.650: E/AndroidRuntime(25021): at android.view.ViewRootImpl.draw(ViewRootImpl.java)
11-06 12:05:53.650: E/AndroidRuntime(25021): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java)
11-06 12:05:53.650: E/AndroidRuntime(25021): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java)
11-06 12:05:53.650: E/AndroidRuntime(25021): at android.os.Handler.dispatchMessage(Handler.java)
11-06 12:05:53.650: E/AndroidRuntime(25021): at android.os.Looper.loop(Looper.java)
11-06 12:05:53.650: E/AndroidRuntime(25021): at android.app.ActivityThread.main(ActivityThread.java)
11-06 12:05:53.650: E/AndroidRuntime(25021): at java.lang.reflect.Method.invokeNative(Native Method)
11-06 12:05:53.650: E/AndroidRuntime(25021): at java.lang.reflect.Method.invoke(Method.java)
11-06 12:05:53.650: E/AndroidRuntime(25021): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
11-06 12:05:53.650: E/AndroidRuntime(25021): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
11-06 12:05:53.650: E/AndroidRuntime(25021): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:7)
您可以通过将清单文件编辑为
来控制各个活动的硬件加速<application android:hardwareAccelerated="true">
<activity ... />
<activity android:hardwareAccelerated="false" />
答案 1 :(得分:3)
答案为here。简而言之:它不再受支持,但如果禁用硬件加速,仍可以使用它。有关详细信息,请参阅帖子。
答案 2 :(得分:1)
即使我在这里得到了同样的错误,答案也帮助我运行了应用程序Android UnsupportedOperationException at Canvas.clipPath
答案 3 :(得分:0)
我遇到了同样的UnsupportedOperationException问题 - 当我有一个试图使用Canvas clipPath()的视图时,它只会在运行4.0.3的设备上崩溃。你可以看到我是如何解决它的here。
答案 4 :(得分:0)
随着Android的新版本支持clipPath()
并启用硬件加速,这可能是一个更好的解决方案:
try {
canvas.clipPath(path);
} catch (UnsupportedOperationException exception) {
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
try {
canvas.clipPath(path);
} catch (UnsupportedOperationException exception2) {
// shouldn't happen, but just in case
}
}