gpt4 book ai didi

Android Get Mapview on Fling 停止动画

转载 作者:太空狗 更新时间:2023-10-29 15:22:44 25 4
gpt4 key购买 nike

我需要限制我的用户可以在 map View 中导航到的区域(除非他们会得到一个空白屏幕!)。我创建了一个扩展 mapview 并覆盖 onTouchEvent 的类。我正在检测“ACTION_UP” Action 并检查此处的坐标并在必要时重新定位 map 。一切正常,直到用户“抛出” map 。我可以检测到“向上”和那个点的屏幕坐标,但 map 仍在移动,所以我检测到的坐标不正确。

我需要知道屏幕停止移动时的位置!

    @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();
}

它对于简单的移动 Action 非常有效( map 停止并没有跳回)但是在 throw 时仍然有一个“有趣的”倾斜效果......

关于Android Get Mapview on Fling 停止动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5950429/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com