如何在android中拖动图像按钮
我在我的应用程序中使用ImageButton
。通过使用 onTouch
事件和 onTouchListener
我响应触摸事件。 触摸事件完成后,我只是在目标位置显示 ImageButton
。 相反,我希望它看起来像拖动 ImageButton
。谁能指出我正确的方向。
I'm using ImageButton
's in my application. By using onTouch
event and onTouchListener
I'm responding to the touch events.
Once the touch event was completed I'm just displaying the ImageButton
at target location.
Instead I wanted it to look like dragging of ImageButton
. Can anyone point me in the right direction.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这个博客有两个非常好的有关如何使用触摸事件在屏幕上移动任何类型视图的示例。
This blog has two very nice examples of how you can use touch events to move any kind of view around the screen.
我不确定我是否明白问题所在。您写了“一旦触摸事件完成[...]” - 这是否意味着您可以在一种情况下使用它,但在其他情况下则不行?您是否认为当 MotionEvent 的操作为
MotionEvent.ACTION_UP
时触摸事件已完成?如果您已经使该部分正常工作,那么为什么不为操作MotionEvent.ACTION_MOVE
重新使用相同的代码呢?I'm not sure I understand what the problem is. You wrote "Once the touch event was completed [...]" - does that mean you've got it to work in one situation but not others? Are you considering that the touch event is completed when the action of the MotionEvent is
MotionEvent.ACTION_UP
? If you've got that part working, then why not just re-use that same code for the actionMotionEvent.ACTION_MOVE
?定义一个扩展 imagebutton 的自己的视图,定义一个可绘制的“活动”状态并设置(或重置)可绘制的 onclick
Define a own view wich is extending imagebutton, define a drawable for "active" state and set (or reset) the drawable onclick