Android Canvas didn't draw Path when Path's point out of view

大兔子大兔子 提交于 2020-01-01 08:54:08

问题


I ran into some problem with Android Canvas when drawing path. My case is that i have a relative layout work like a map view ( not using google api or something like that ). I have to draw a path onto that view.

    canvas.drawPath(polyPath, borderPaint);

I also have to draw other type like circle, polygon using canvas as well. Everytime we zoom in or zoom out, we re-calculate path point to match with zoom level. When using old api like android 2.3.3, there no problem at all. But for newer api like android 4.x, when we zoom in, there are point which have position out of visible view ( like -300,-300 for example ). After a while zoom in, the visible area only display a small part of my path. And then suddenly the whole path disappear. If we zoom out, it appear again. It like canvas stop rendering those ( other object still display like icon ) Same thing go for circle, oval or polygon.

So i'm not sure if there any change in how canvas draw thing ? Is there anything i'm missing about drawing using canvas?


回答1:


Add this line in the initialization of the view

setLayerType(View.LAYER_TYPE_SOFTWARE, null);

also see this guide for hardware level supported API

google API



来源:https://stackoverflow.com/questions/19650273/android-canvas-didnt-draw-path-when-paths-point-out-of-view

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