在MapView之外再套一層RelativeLayout或者LinearLayout顿天,并且重寫RelativeLayout或者LinearLayout
代碼如下:
public class MyRelLayout extends RelativeLayout{
private ScrollView mScrollView;
//這三個方法必須有
public MyRelLayout(Context context) {
super(context);
}
public MyRelLayout(Context context,Attribute Setattrs) {
super(context,attrs);
}
public MyRelLayout(Context context,AttributeSet attrs,int defStyleAttr) {
super(context,attrs,defStyleAttr);
}
public void setScrollView(ScrollView scrollView){
this.mScrollView=scrollView;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
Log.d("maprel","--------:onInterceptTouchEvent");
if(ev.getAction()==MotionEvent.ACTION_UP) {
mScrollView.requestDisallowInterceptTouchEvent(false);//手離開地圖ScrollView恢復(fù)原來的滑動狀態(tài)
}else{
mScrollView.requestDisallowInterceptTouchEvent(true);//調(diào)用此方法后ScrollView的touch事件將不會被觸發(fā)
}
return false;
}
}