How to make gesture of mapview works in scrollview
Customize scrollview to disable touch events in MapView rect.
public final class MapScrollView extends ScrollView {
private View touchView;
private final Rect rect = new Rect();
public MapScrollView(Context context) {
this(context, null);
}
public MapScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
touchView = findViewById(R.id.map_view);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
final int action = ev.getAction();
final int actionMasked = action & MotionEvent.ACTION_MASK;
if (actionMasked == MotionEvent.ACTION_DOWN) {
int x = (int) ev.getRawX();
int y = (int) ev.getRawY();
touchView.getGlobalVisibleRect(rect);
if (rect.contains(x, y)) {
return false;
}
}
return super.onInterceptTouchEvent(ev);
}
}