DEMO地址:https://github.com/zhaopingfu/GDTest/tree/master/app/src/main/java/com/pf/gdtest/widget
之前用高德地图,放在ScrollView中,两个都是可以滑动的控件,所以有点滑动冲突的问题
解决方法:将地图控件外层的父布局重写,当事件过来的时候告诉scrollview这个事件我要处理,让他不要拦截
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) {
if (scrollView != null) {
scrollView.requestDisallowInterceptTouchEvent(false);
}
} else {
if (scrollView != null) {
scrollView.requestDisallowInterceptTouchEvent(true);
}
}
return false;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return true;
}
}