0
如何自動滾動滾動視圖內的地圖,如Expedia應用?滾動滾動視圖時自動在滾動視圖內滾動地圖
如何自動滾動滾動視圖內的地圖,如Expedia應用?滾動滾動視圖時自動在滾動視圖內滾動地圖
得到了解決方案。 首先創建自定義滾動視圖。 將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);
}