4

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?

LOG_TAG
  • 19,894
  • 12
  • 72
  • 105
Dan Ponce
  • 636
  • 1
  • 8
  • 24

4 Answers4

4

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">
David Jarvis
  • 2,769
  • 2
  • 15
  • 26
2

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.

zeenosaur
  • 888
  • 11
  • 16
0

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" />
SUR4IDE
  • 1,003
  • 1
  • 5
  • 11
-1

Add Google Maps map fragment into LinearLayout and add android:nestedScrollingEnabled="true" this line into LinearLayout.

Ole Pannier
  • 3,208
  • 9
  • 22
  • 33