android 如何调用invalidate(Rect)
我创建了扩展 LinerLayout 的类并在视图上添加了许多元素,还添加了圆圈 等 canvas.drawCircle(100, 100, 10) ,当我实现 onTouchEvent 时,我不确定如何仅重绘该元素(圆)。在“矩形”中设置哪些参数,以便我可以将其发送到无效(矩形)。
谢谢。
I create class that extends LinerLayout and add many elements on view, also I add circle with
etc canvas.drawCircle(100, 100, 10) and when I implement onTouchEvent I am not sure how to redraw only that element(circle). which parameters to set in "Rect" so I can send it to invalidate(Rect).
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于具体的示例,我认为这个代码示例可以满足您的要求。我将你的坐标移动到变量(cx,cy,r)中只是为了使其清楚。根据您提到的内容,我认为您会从 LinearLayout 子类中调用它。
我在所有边上添加了一个额外的像素,只是为了稍微重叠圆圈,以确保整个区域无效。根据我的经验,您似乎可以包含负值或超出画布尺寸的值。
For the specific example, I think this code example does what you want. I moved your coordinates into variables (cx, cy, r) just to make it clear. Based on what you mentioned, I think you would call this from within your LinearLayout subclass.
I added an extra pixel on all sides just to overlap the circle a bit to ensure the entire area is invalidated. Based on my experience, it looks like you can include negative values or values that exceed the dimensions of the canvas.