2017-12-10 21 views
0

NestedScroollView内のMapViewに問題があります。 Googleマップが正しく表示されますが、地図をスクロールしようとすると機能しません。私はこれを解決する方法を知らない。誰でも助けてくれますか?ありがとう!NestedScrollView内のMapViewが滑らかにスクロールしない

私のコードです: 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; 
    } 
..... 
} 

答えて

0

私は同じ問題を抱えていました。ここに解決策があります。カスタム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; 
} 
+0

私はあなたのソリューションを試しましたが、まだ動作しません。私は水平に私のCustomMapViewをスクロールできません... – Federico

関連する問題