1

我正在尝试将 ESRI 映射添加到我位于 NestedScrollView 中的片段中。它加载得很好,但是当我移动地图时,如果我删除 NestedScrollView 一切正常,它就不会顺利移动。

这是我在 NestedScrollView 中的 ESRI 地图视图

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.core.widget.NestedScrollView
        android:id="@+id/nestedScrollView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="@dimen/spacing_normal">

    <com.esri.arcgisruntime.mapping.view.MapView
            android:id="@+id/mapView"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

     </com.esri.arcgisruntime.mapping.view.MapView>

 </androidx.core.widget.NestedScrollView>
</LinearLayout>

我尝试通过从此处引用将 customTouchListener 设置为映射视图,例如:

MyTouchListener tl = new MyTouchListener(this, mMapView);   
mMapView.setOnTouchListener(tl);

MyTouchListener 类:

class MyTouchListener(context: Context, m: MapView) : DefaultMapViewOnTouchListener(context, m) {

    private var sv: NestedScrollView? = null

    override fun onTouch(v: View?, event: MotionEvent): Boolean {
        v?.performClick()
        sv = v!!.findViewById(R.id.nestedScrollView)
        val action = event.action
        when (action) {
            MotionEvent.ACTION_DOWN ->
                // will disable the scrollview from being able to
                // intercept the touch events for the mapview
                sv?.requestDisallowInterceptTouchEvent(true)

            MotionEvent.ACTION_UP ->
                // gives control back over to the scrollview
                sv?.requestDisallowInterceptTouchEvent(false)
        }

        super.onTouch(v, event)
        return true
    }

}

但还是同样的问题,地图移动不顺畅。

4

1 回答 1

1

It will disable the scrollView from being able to intercept the touch events for the mapView

override fun onTouch(view: View?, event: MotionEvent?): Boolean {
    activity?.nestedScrollView?.requestDisallowInterceptTouchEvent(true)
    return super.onTouch(view, event)
}

Also do it in addViewpointChangedListener

mapView.addViewpointChangedListener {
    activity?.nestedScrollView?.requestDisallowInterceptTouchEvent(true)
}
于 2018-12-26T08:18:37.660 回答