0

如何自动滚动像Expedia Application这样的滚动视图内的地图?

4

1 回答 1

0

得到了解决方案。首先创建自定义滚动视图。将地图视图放在滚动视图中。然后在自定义滚动视图的 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);       
}
于 2014-03-12T11:27:38.590 回答