Android 在 Fling 上获取 Mapview 停止动画
我需要限制用户可以在地图视图中导航到的区域(除非他们会看到空白屏幕!)。 我创建了一个扩展地图视图并覆盖 onTouchEvent 的类。 我正在检测“ACTION_UP”操作并检查此处的坐标,并在必要时重新定位地图。一切正常,直到用户“扔”地图。我可以检测到“向上”和此时屏幕的坐标,但地图仍在移动,因此我检测到的坐标不是正确的。
我需要知道屏幕停止移动时的位置!
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_UP ) {
//get coords of screen corners and calculate if the map is still in view.
}
我一直在寻找这个问题的答案,但很多人都在问这个问题,但似乎没有任何解决方案?
有人设法做到这一点吗?
贝克斯
I need to limit the area my users can navigate to in the mapview (unless they'll get a blank screen!).
I have created a class that extends the mapview and overridden the onTouchEvent.
I am detecting the action "ACTION_UP" and checking the coords here and repostioning the map if I have to. Everything works fine until the user "flings" the map. I can detect the "Up" and the coordinates of the screen at that point, but the map is still moving so the coordinates I detect aren't the correct ones.
I need to know the screen position when it's stopped moving!
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_UP ) {
//get coords of screen corners and calculate if the map is still in view.
}
I have been looking for a fair amount of time for the answer to this but lots of people are asking the question, but there don't appear to be any solutions around?
Has anyone managed to do this?
Bex
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我用来重写 MapView 的computeScroll() 方法:
它对于简单的移动动作非常有效(地图停止不会跳回),但在投掷时仍然具有“有趣的”倾斜效果......
i use to override the computeScroll() method of the MapView:
it works quite well for simple move actions ( the map stops has does not jump back ) but still has a "funny" tilt effect when flinging...
我也有同样的问题。你的方法很好,只需要在另一个地方赶上事件即可。您可以重写 MapView 类的“DispatchTouchEvent”方法(或使用 MapFragment 采取类似的方法),并使其跳过 MotionEvent.ACTION_UP 事件:
I had the same problem. Your approach is good, just need to catch the event on another place. You can override "DispatchTouchEvent" method of MapView class (or take similar approach using MapFragment), and there you make it skip MotionEvent.ACTION_UP event: