Android: Draw a view on canvas

99封情书 提交于 2019-12-05 09:47:11

Each View draws its contents within its own coordinate system, with (0, 0) at the top-left. If you want it to appear elsewhere, you can set a new transformation matrix on your Canvas.

Solution is to translate canvas:

canvas.save();
canvas.translate(left, top);            
view.draw(canvas);
canvas.restore();

because the coordinate system used in the Canvas starts from the top left corner instead of doing that define your Custom View and override the onDraw() method and inside it position your view as you like

use drawChild(canvas,child,getDrawingTime()); instead of child.draw(canvas)

drawChild will calc child's top and left margin

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