NestedScrollView内部的MapView滚动不平滑

MapView inside NestedScrollView not scrolling smooth(NestedScrollView内部的MapView滚动不平滑)

本文介绍了NestedScrollView内部的MapView滚动不平滑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在NestedScroollView内的MapView有问题。 我的Google地图显示正确,但当我尝试滚动地图时,它不起作用。我不知道怎么解决这个问题。有谁可以帮我?谢谢!

这是我的代码: dog_view.xml

...
<android.support.v4.widget.NestedScrollView
    android:fillViewport="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/nestedScroll"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <include layout="@layout/dog_view_layout"
        android:layout_height="match_parent"
        android:layout_width="match_parent"/>

</android.support.v4.widget.NestedScrollView>

dog_view_layout.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:background="#000"
    android:layout_height="wrap_content"
    android:paddingTop="20dp">
    <com.google.android.gms.maps.MapView
        android:id="@+id/mapView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</RelativeLayout>

DogFragment

...
    MapView mMapView;
    private GoogleMap googleMap;


    public DogFragment(){

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.dog_view, container, false);
        this.dog = getArguments().getParcelable("data");
        mMapView = (MapView) rootView.findViewById(R.id.mapView);
        mMapView.onCreate(savedInstanceState);
        mMapView.onResume(); // needed to get the map to display immediately
        try {
            MapsInitializer.initialize(getActivity().getApplicationContext());
        } catch (Exception e) {
            e.printStackTrace();
        }

        mMapView.getMapAsync(new OnMapReadyCallback() {
            @Override
            public void onMapReady(GoogleMap mMap) {
                googleMap = mMap;
                googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
                googleMap.setMyLocationEnabled(true);
            }
        });
        setLayout(rootView);
        return rootView;
    }
.....
}

推荐答案

我遇到了同样的问题。以下是解决方案。我创建了一个自定义MapView并覆盖了onTouchEvent(),如下所示。

 @Override
public boolean onTouchEvent(MotionEvent ev) {
    int action = ev.getAction();
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        // Disallow ScrollView to intercept touch events.
        this.getParent().requestDisallowInterceptTouchEvent(true);
        break;

    case MotionEvent.ACTION_UP:
        // Allow ScrollView to intercept touch events.
        this.getParent().requestDisallowInterceptTouchEvent(false);
        break;
    }

    // Handle MapView's touch events.
    super.onTouchEvent(ev);
    return true;
}

这篇关于NestedScrollView内部的MapView滚动不平滑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:NestedScrollView内部的MapView滚动不平滑