Android:可拖动 Toast,还是替代方案?
我在画布上绘制了许多位图,并使用 MotionEvents 让我可以拖动它们。
当按下每个项目时,我想显示一个 Toast 或类似 Toast 的迷你信息面板,用于跟踪在 ACTION_MOVE 期间拖动的位图的移动。 “Toast”将在 ACTION_DOWN 时出现,并在 ACTION_UP 时消失。
使用 Toast 的问题是我必须给它一个持续时间,而且一旦它显示出来我就无法改变它的位置。除非我可以为每个 ACTION_MOVE 杀死 Toast,并立即在当前坐标处显示一个新的 Toast? (抱歉,此时大声思考,无法访问我的开发机器进行测试......)
我不知道还有哪些其他选项可以实现这一目标,并且我非常感谢社区的建议。
I'm drawing a number of bitmaps on a canvas, and using MotionEvents to let me drag them around.
When each item is pressed, I'd like to display a Toast, or, Toast-like mini information-panel that tracks the movement of the bitmap being dragged during an ACTION_MOVE. The "Toast" would appear on ACTION_DOWN and vanish on ACTION_UP.
The problem with using Toast is that I have to give it a duration, and, also, I can't change its position once it has been displayed. Unless I can kill the Toast for each ACTION_MOVE, and display a new one right away at the current coordinates? (Sorry, thinking aloud at this point, can't get to my dev machine to test...)
I don't know what other options there might be to achieve this, and I'd very much appreciate suggestions from the community.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
希望这有帮助,刚刚启动它,甚至可以编译!
Hope this helps, just whipped it up, might even compile!
由于您已经提到的原因,Toast 不适合这种情况。最好在 Canvas 上定义一个区域并使用 drawText 在那里绘制消息字符串。将其放入 onDraw 方法中,并在需要更新文本或留言板位置时调用 invalidate。
A Toast isn't suitable in this case for reasons you already mentioned. It will be better to define a region on the Canvas and draw the message string there using drawText. Put this in the onDraw method and call invalidate whenever you need to update the text or the position of the message board.