如何在滚动视图中自动滚动地图,如Expedia应用程序
发布于 2014-03-12 11:27:38
找到解决办法了。首先创建自定义滚动视图。将mapview放在滚动视图中。然后在自定义滚动视图的onScrollChanged上滚动地图视图,
在CustomScrollView.java上:
protected void onScrollChanged(int l, int t, int oldl, int oldt)
{
super.onScrollChanged(l, t, oldl, oldt);
scrollMap(l,t);
}在YourActivity.java上:
public void scrollMap(int x, int y)
{
int scrollLength = scrollView.getMeasuredHeight();
int mapViewHeight = mapView.getMeasuredHeight();
int mapViewCenter = (int)(mapViewHeight/2);
int scrollMapHeight = (mapViewCenter + ((int)((mapViewHeight*y)/scrollLength)));
scrollMapHeight = (int)((mapViewCenter - scrollMapHeight)/(1.5));
if(scrollMapHeight<0)
mapView.scrollTo(x, scrollMapHeight);
}https://stackoverflow.com/questions/15853877
复制相似问题