Android UnsupportedOperationException at Canvas.clipPath

蹲街弑〆低调 提交于 2019-11-30 13:00:43

On ICS devices, there is a developer option to force hardware acceleration even if the app doesn't request it. That is what is causing the crashes. You should be able to use something like this to force it to use software rendering:

if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
   myCusomView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}

I guess you can draw your view to a off-screen bitmap and copy the bitmap to the on-screen canvas. For instance,

protected void draw(Canvas canvas) {
    if (mHidden) {
        return;
    }

    Bitmap bitmap = createOffScreenBitmap();
    canvas.drawa(bitmap,0f, 0f, null);

}


private Bitmap drawOffScreenBitmap(){

    // Draw whatever you want to draw right here.
}

Also, you can use PorterDuffxfermode that supports hardware acceleration, instead of clippath.

myCustomView = view class name or use this

if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
   this.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}

I get the solution using that method.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!