如何在 TouchEvent 之后重绘视图?
我对 View
进行了子类化,以获得用户可以用手指“绘图”的视图。我实现了接口View.OnTouchListener
。
如何在 onTouch
方法中触发视图的重绘?我需要实现线程/可运行吗?我认为 invalidate()
会触发重绘,但这不起作用。
I subclassed View
to get an View on which the user can "draw" with his fingers. I implemented the Interface View.OnTouchListener
.
How can I trigger within the onTouch
method the redraw of the View? Do I need to implement a Thread / Runnable? I thought that invalidate()
triggers the redraw, but this doesn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需在视图的 onTouchEvent 方法中调用 this.invalidate ,它确实应该有效除非您没有在 onDraw 方法中执行正确的操作。确保您引用正确的画布进行绘制您重写的 onDraw 方法中的内容而不是例如构造函数。
Just call this.invalidate in the onTouchEvent method of your view, it really should work unless you're not doing the proper thing in your onDraw method. Make sure you're referencing to the right canvas an draw the thing in your overridden onDraw method instead of for example the constructor.