滚动滚动视图时自动在滚动视图内滚动地图
答
得到了解决方案。 首先创建自定义滚动视图。 将scrollview放入滚动视图中。 然后在自定义滚动型onScrollChanged,滚动的MapView一样,
在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);
}