I have a google map fragment on the top of my bottom sheet dialog. I disabled the draggable touch action on the bottom sheet behavior so that I could control the map. The problem is that I can't scroll the map using up or down touch actions because of my bottom sheet draggable disabled. I was thinking to disable the touch action of the bottom sheet behavior when the user touches the map but I don't know how to do this. How can I fix this?
-
Did you find any solution? – Andriy Antonov Mar 18 '17 at 09:03
-
I just used a DialogFragment for this. It works fine – Dan Ponce Mar 20 '17 at 16:09
4 Answers
Try adding nestedScrollingEnabled="true"
to the bottom sheet layout:
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="true"
app:behavior_hideable="true"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">

- 2,769
- 2
- 15
- 26
I have a BottomSheetDialogFragment
(parent View
) that contains SupportMapFragment
(child View
). Panning the map works only for horizontal gestures. As OP mentioned, this is because BottomSheet
and Map
touch events are in conflict when it comes to vertical gestures.
This is how I handled it. My BottomSheetDialogFragment
implements OnMapReadyCallback
and GoogleMap.OnCameraMoveStartedListener
.
override fun onMapReady(p0: GoogleMap) {
p0.setOnCameraMoveStartedListener(this)
}
override fun onCameraMoveStarted(reason: Int) {
when(reason) {
GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE -> {
// The user gestured on the map
childView?.parent?.requestDisallowInterceptTouchEvent(true)
}
GoogleMap.OnCameraMoveStartedListener.REASON_API_ANIMATION -> {
// The user tapped something on the map
childView?.parent?.requestDisallowInterceptTouchEvent(true)
}
GoogleMap.OnCameraMoveStartedListener.REASON_DEVELOPER_ANIMATION -> {
// The app moved the camera
childView?.parent?.requestDisallowInterceptTouchEvent(true)
}
}
}
When set as true
, requestDisallowInterceptTouchEvent()
does not allow the parent View
to intercept with the touch events of the child View
. I can now zoom in/out the map (horizontal and vertical gestures) in my bottom sheet dialog fragment.

- 888
- 11
- 16
I added android:nestedScrollingEnabled="true" to the FragmentContainerView holding my Google map.
Now, I can maneuver in the Google map and use my Bottom Sheet normally.
<androidx.fragment.app.FragmentContainerView
android:id="@+id/map"
android:nestedScrollingEnabled="true"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/title_bg" />

- 1,003
- 1
- 5
- 11
Add Google Maps map fragment into LinearLayout
and add android:nestedScrollingEnabled="true"
this line into LinearLayout
.

- 3,208
- 9
- 22
- 33

- 1
- 2