2

Mein Problem: Ich kann nur innerhalb meiner MapView nach oben und unten scrollen, nicht links und rechts.Android MapView nur vertikal scrollen

Ich habe eine MapView in meinem LinearLayout, die von einer geschachtelten Scroll-Ansicht gespeichert wird. Also meine layout.xml sieht wie folgt aus:

<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical"> 
    <LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    ... 

    <com.google.android.gms.maps.MapView 
     android:layout_width="match_parent" 
     android:layout_height="160dp" 
     android:layout_margin="10dp" 
     android:id="@+id/jd_map_view"/> 
    ... 
</LinearLayout> 

ich das MapView in meinem Fragment bin initialisiert, holded durch einen TabLayout, wie folgt aus:

mapView = (MapView) mRootView.findViewById(R.id.jd_map_view); 
mapView.onCreate(savedInst); 
mapView.onResume(); 
mapView.getMapAsync(new OnMapReadyCallback() { 
      @Override 
      public void onMapReady(GoogleMap googleMap) { 
       LatLng latlng = new LatLng(mLat, mLng); 
       googleMap.addMarker(new MarkerOptions().position(latlng)); 
       CameraUpdate center= CameraUpdateFactory.newLatLng(latlng); 
       CameraUpdate zoom=CameraUpdateFactory.zoomTo(14); 

       googleMap.moveCamera(center); 
       googleMap.animateCamera(zoom); 
      } 
     }); 

Es funktioniert mehr oder weniger richtig, bedeutet, ich sehe eine Karte, sehe meinen Marker und die Karte ist auf der richtigen Position. Aber leider kann ich nicht rechts scrollen ...

+1

Ich habe noch nie eine Karte in einer verschachtelten Bildlaufansicht setzen. Wenn Sie ein Rahmenlayout für Ihre Fragmente verwenden und das Mapfragment hinzufügen, sollte es funktionieren. –

+0

Wo wollen Sie das Rahmenlayout verwenden? anstelle des linearen Layouts oder als Platzhalter für das MapFragment? – Steeve

+0

als Platzhalter –

Antwort

0

Würde das nicht für Sie arbeiten?

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <fragment 
     android:id="@+id/map" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     class="com.google.android.gms.maps.MapFragment" /> 

</RelativeLayout> 
+0

leider nicht:/ – Steeve

0

Anstatt ein Scroll-Layout verwenden, wird die Karte automatisch in jede Richtung bewegen, wenn Sie es in einem einfachen framelayout setzen.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:tools="http://schemas.android.com/tools" 
      android:id="@+id/main" 
      android:layout_height="match_parent" 
      android:layout_width="match_parent" 
      android:paddingBottom="@dimen/activity_vertical_margin" 
      android:paddingLeft="@dimen/activity_horizontal_margin" 
      android:paddingRight="@dimen/activity_horizontal_margin" 
      android:paddingTop="@dimen/activity_vertical_margin" 
      tools:context="thiscode.databasedemo.Main"> 

    <TextView 
     android:id="@+id/tv" 
     // adjust margins for your need. 
     android:layout_marginTop="30dp" 
     // etc 


    <FrameLayout 
     android:id="@+id/fl" 
     android:layout_below="@+id/tv" 
     android:layout_height="fill_parent" 
     // adjust margins for your need. 
     android:layout_marginBottom="0dp" 
     android:layout_marginLeft="0dp" 
     android:layout_marginRight="0dp" 
     android:layout_marginTop="40dp" 
     android:layout_width="match_parent"> 

     <fragment 
      android:id="@+id/map" 
      android:layout_height="fill_parent" 
      android:layout_width="match_parent" 
      android:name="com.google.android.gms.maps.MapFragment"/> 
    </FrameLayout> 
</RelativeLayout> 

Die Aktivität:

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.act_main); 
    // create class object 
    fragmentManager = getFragmentManager(); 
    // 
    try { 
     GoogleMap googleMap = 
       ((MapFragment) fragmentManager.findFragmentById(R.id.map)) 
         .getMap(); 
     // example data. 
     googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID); 
     LatLng latlng = new LatLng(0.083037, 106.704897); 
     CameraPosition cameraPosition = 
       new CameraPosition.Builder().target(latlng).zoom(2).build(); 
     googleMap.animateCamera(
       CameraUpdateFactory.newCameraPosition(cameraPosition)); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
+0

Ok ich muss ins Bett gehen, ich hoffe, dass es aussortiert, es funktioniert ich nahm es von Funktionscode. Spielen Sie damit und ändern Sie nicht das Layout-Design, um es tatsächlich zu testen. Hinterlasse einen Kommentar, wenn du es brauchst, aber ich werde nicht für eine Weile zurück sein. –

+0

Danke, ich werde es versuchen. Nur um Missverständnisse zu vermeiden: Ich brauche NestedScrollView, weil der Inhalt zu groß ist, nicht für die Map. Ich möchte ein normales ScrollView mit einem MapView darin haben, das aktiv wird, wenn ich darin blättern werde. – Steeve

+0

Weiter: Ich möchte die Karte in einem Fragment zeigen, nicht in einer Aktivität. – Steeve