android-fragments GoogleMap触摸底部表单对话框

tv6aics1  于 2022-11-14  发布在  Android
关注(0)|答案(4)|浏览(136)

我有一个谷歌Map片段在我的底部工作表对话框的顶部。我禁用了底部工作表行为上的可拖动触摸动作,以便我可以控制Map。问题是,我不能使用向上或向下触摸动作滚动Map,因为我的底部工作表可拖动禁用。我想禁用底部工作表行为的触摸动作时,用户触摸Map,但我没有I don“我不知道怎么做,我该怎么修呢?

zwghvu4y

zwghvu4y1#

尝试将nestedScrollingEnabled="true"添加到底部图纸布局:

<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">
cig3rfwq

cig3rfwq2#

我有一个BottomSheetDialogFragment(父View),它包含SupportMapFragment(子View)。平移Map只对水平手势有效。正如OP提到的,这是因为BottomSheetMap触摸事件在垂直手势时发生冲突。
我的BottomSheetDialogFragment实现了OnMapReadyCallbackGoogleMap.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)
        }
    }
}

当设置为true时,requestDisallowInterceptTouchEvent()不允许父View拦截子View的触摸事件。我现在可以在我的底部表单对话框片段中放大/缩小Map(水平和垂直手势)。

arknldoa

arknldoa3#

我将**android:nestedScrollingEnabled=“true”**添加到包含我的谷歌Map的FragmentContainerView中。
现在,我可以在谷歌Map中机动,正常使用我的底表。

<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" />
htzpubme

htzpubme4#

将Google MapsMap片段添加到LinearLayout中,并将android:nestedScrollingEnabled="true"此行添加到LinearLayout中。

相关问题