1、自定义一个viewGroup,继承Relativelayout(或者别的layout)
重点是重写了onInterceptTouchEvent(MotionEvent ev)和onTouchEvent(MotionEvent event)
/**
*解决地图在主scrollview中滑动冲突的问题由于MapView被定义成final class,所以只能在容器中操作了
*/
public class MapContainer extends RelativeLayout {
private ScrollView scrollView;
public MapContainer(Context context) {
super(context);
}
public MapContainer(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void setScrollView(ScrollView scrollView) {
this.scrollView = scrollView;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_UP) {
scrollView.requestDisallowInterceptTouchEvent(false);
}else {
scrollView.requestDisallowInterceptTouchEvent(true);
}
return false;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return true;
}
}