Android 滚动scrollview时自动滚动scrollview内的地图

Android 滚动scrollview时自动滚动scrollview内的地图,android,android-mapview,android-scrollview,Android,Android Mapview,Android Scrollview,如何像Expedia应用程序一样在scrollview中自动滚动地图?得到了解决方案。 首先创建自定义滚动视图。 将mapview放在scrollview中。 然后在自定义scrollview的onScrollChanged上,滚动地图视图,如下所示: 在CustomScrollView.java上: protected void onScrollChanged(int l, int t, int oldl, int oldt) { super.onScrollChanged(l, t

如何像Expedia应用程序一样在scrollview中自动滚动地图?

得到了解决方案。 首先创建自定义滚动视图。 将mapview放在scrollview中。 然后在自定义scrollview的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);       
}
publicsvoidscrollmap(intx,inty)
{
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));
如果(滚动贴图高度)