I am working with Google Map,
My case is that I have a map fragment inside the ScrollView and I need to scroll the map only with two finger if user touches only one finger map should not work and normal Scroll View should work.
This is what i tried so far -
transparent_image.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
switch (action & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_POINTER_DOWN:
showMessage("Double finger ACTION_POINTER_DOWN");
googleMap.getUiSettings().setScrollGesturesEnabled(false);
scroll_view.requestDisallowInterceptTouchEvent(true);
return true;
case MotionEvent.ACTION_POINTER_UP:
showMessage("Double finger ACTION_POINTER_UP");
googleMap.getUiSettings().setScrollGesturesEnabled(true);
scroll_view.requestDisallowInterceptTouchEvent(false);
return true;
default:
return true;
}
}
});
For more details check this https://maps-apis.googleblog.com/2016/11/smart-scrolling-comes-to-mobile-web-maps.html
That behavior of native Android application you can achieve when:
1) disable
ScrollView
scrolling and enableGoogleMap
scrolling when user placed two finger onMapFragment
;2) enable
ScrollView
scrolling and disableGoogleMap
scrolling in other case.For disabling/enabling
ScrollView
scrolling by condition, you need to extendScrollView
and override theonTouchEvent()
method to returnfalse
when some condition is matched, for example, as in this answer of Josep Earl:Enable/disable scroll gestures at
GoogleMap
you can easily callingsetAllGesturesEnabled()
andsetScrollGesturesEnabled()
onGoogleMap.getUiSettings()
object and for determining touches of two fingers onMapFragment
you can use approach, based on this answer of community wiki:MapFragment
in this case can be like that:and
MainActivity
like that (there is no need to add marker on map - it's just for test):and, finally,
activity_main.xml
forMainActivity
, for example, can be like this:and that's it.