在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恢复原来的滑动状态
}else{
mScrollView.requestDisallowInterceptTouchEvent(true);//调用此方法后ScrollView的touch事件将不会被触发
}
return false;
}
}
网友评论