4

使用 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)
4

5 回答 5

7

您可以通过编辑清单文件来控制单个活动的硬件加速

<application android:hardwareAccelerated="true">
<activity ... />
<activity android:hardwareAccelerated="false" />

于 2013-06-20T06:16:39.180 回答
3

这里有一个答案。简而言之:它不再受支持,但如果您禁用硬件加速,您仍然可以使用它。有关更多信息,请参阅帖子。

于 2012-11-06T10:49:12.313 回答
1

即使我在这里遇到同样的错误也是答案,它帮助我在 Canvas.clipPath 运行应用程序 Android UnsupportedOperationException

于 2015-02-03T10:22:07.353 回答
0

我遇到了同样的 UnsupportedOperationException 问题——当我有一个尝试使用 Canvas clipPath() 的视图时,它只会在运行 4.0.3 的设备上崩溃。你可以在这里看到我是如何解决的。

于 2014-03-25T18:57:55.547 回答
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 
    }
}
于 2017-10-12T20:24:39.637 回答