Android 在 Fling 上获取 Mapview 停止动画

2024-02-08

我需要限制用户可以在地图视图中导航到的区域(除非他们会看到空白屏幕!)。 我创建了一个扩展地图视图并覆盖 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.
}

我一直在寻找这个问题的答案,但很多人都在问这个问题,但似乎没有任何解决方案?

有人设法做到这一点吗?

Bex


我用来重写 MapView 的computeScroll() 方法:

/**
 * checks restriction on pan bounds and locks the map. if the map is locked
 * (via mapController.getCenter()) this method returns true
 * 
 * @return TRUE if map has been locked
 */
private boolean restrictPanOnBounds() {
  if (this.minLatitudeE6 == Integer.MIN_VALUE)
    return false;

  GeoPoint center = getMapCenter();
  int cLat = center.getLatitudeE6();
  int cLong = center.getLongitudeE6();

  Integer nLat = null, nLong = null;

  if (cLat < this.minLatitudeE6)
    nLat = this.minLatitudeE6;
  else if (cLat > this.maxLatitudeE6)
    nLat = this.maxLatitudeE6;

  if (cLong < this.minLongitudeE6)
    nLong = this.minLongitudeE6;
  else if (cLong > this.maxLongitudeE6)
    nLong = this.maxLongitudeE6;

  if (nLat != null || nLong != null) {
    getController().setCenter(new GeoPoint(nLat != null ? nLat : cLat, nLong != null ? nLong : cLong));
    return true;
  } else {
    return false;
  }
}

@Override
public void computeScroll() {
  if (restrictPanOnBounds())
    getController().stopPanning();
  else
    super.computeScroll();
}

它对于简单的移动动作非常有效(地图停止不会跳回),但在投掷时仍然具有“有趣的”倾斜效果......

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android 在 Fling 上获取 Mapview 停止动画 的相关文章

随机推荐