Android 4.0 compatibility issues with Canvas.clipPath

梦想与她 提交于 2019-12-21 20:40:49

问题


Recently my application received quite a lot comments that "it's not working" on Android Ice Cream Sandwich with CM9. I'm not able to reproduce the error on the emulator running Android 4.0 and thanks to the way android market works there's no way I can't contact those people to ask about the details.

Luckily, one crash error report caught my eye. I'm using Canvas.clipPath to draw rounded corners... and looks like some phones are throwing UnsupportedOperationException when trying to use that function. Quick look at Google reveals that it seems to be a problem when using hardware acceleration in Android 4.0 - so that's the potential reason of received comments.

The question is - what's going on? Weren't applications hardware accelerated in previous android versions? Why such common function isn't supported? What's the workaround?

Example usage of Canvas.clipPath can be found in my other post. Check the accepted answer here: Android rounded corners in ListView

Thanks in advance


回答1:


In ICS, hardware acceleration was turned on by default. Until 4.0, the default was that hardware acceleration was off. Hardware acceleration does not support clipPath (and a few other operations, see more here http://android-developers.blogspot.com/2011/03/android-30-hardware-acceleration.html) I am facing the same issue. As a quick fix I will turn off acceleration for the entire application, and later I will rewrite the code not to use clipPath




回答2:


You can turn off hardware acceleration only on the specific view that is causing problems. Check out my answer here: https://stackoverflow.com/a/14054331/596708



来源:https://stackoverflow.com/questions/8771219/android-4-0-compatibility-issues-with-canvas-clippath

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