告诉View要绘制哪个区域
我的问题可能有点不清楚,但我已经扩展了 View 类并在画布上围绕 (0,0)
生成了许多形状。我想把这个点放在中间,所以我必须告诉View它必须水平绘制,例如,在x-上从-640
到640
轴和垂直方向,例如,y 轴上从 -360
到 360
。
有没有办法告诉视图它必须绘制这些像素而不改变绘制形状的坐标。我只是想告诉视图它必须绘制某些坐标。
我希望能够动态更改绘制的区域。
My question may be a bit unclear, but I have extended the View class and generated a number of shapes on the canvas around (0,0)
. I want to put this point in the middle, so I have to tell the View that it has to draw horizontally, for example, from -640
to 640
on the x-axis and vertically, for example, from -360
to 360
on the y-axis.
Is there a way to tell the view that it has to draw these pixels without changing the coordinates of the drawn shapes. I just want to tell the view that it has to draw certain coordinates.
I want to be able to change dynamically which area is drawn.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我并不是 100% 你想要实现的目标,但是如果你想移动和缩放你的形状,你可以使用画布 翻译 或 scale 方法,将画布移动到在你的形状下。请记住,您转换的是画布,而不是形状,因此必须反向完成转换。您还应该使用画布保存和< a href="http://developer.android.com/reference/android/graphics/Canvas.html#restore%28%29" rel="nofollow">restore 方法用于在转换之间恢复画布位置。
如果您想将任何绘图限制在一个区域,您可以使用画布 clip-methods,例如:
将丢弃该矩形之外的任何绘图。
I'm not 100% what you are trying to achieve, but if you want to move and scale your shapes, you can use the canvas translate or scale methods, to move the canvas to under your shapes. Remember that it is the canvas you translate, and not the shape, so the transformations will have to be done in reverse. You should also use the canvas save and restore methods to restore your canvas position between transformations.
If you instead want to limit any drawing to an area, you can use the canvas clip-methods, for example:
Would case any drawing outside that rectangle to be discarded.