2

問題:MapView内で上下左右にスクロールすることができます。Android MapViewが垂直方向にスクロールするだけです

私はLinearLayoutにMapViewを持っていますが、これはネストされたスクロールビューによって保持されています。だから私のlayout.xmlは次のようになります。

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

私はこのように、TabLayoutによってニコラウス私のフラグメントでのMapViewを、初期化しています:

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); 
      } 
     }); 

それはより多くの作品以下正しく、私が地図を見て、私のマーカーを見て、地図が正しい位置にあることを意味します。しかし、うっかり、私は右にスクロールすることはできません...

+1

私は、ネストされたスクロールビューにマップを入れたことがありません。あなたのフラグメントにフレームレイアウトを使用し、それがうまくいくようにmapfragmentを追加する場合 –

+0

フレームレイアウトをどこで使うのですか?線形レイアウトの代わりに、またはMapFragmentのプレースホルダとして使用できますか? – Steeve

+0

をプレースホルダとして –

答えて

0

これはあなたのために動作しますか?

<?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

残念ながら:/ – Steeve

0

スクロールレイアウトを使用するのではなく、単純なフレームレイアウトにマップを配置すると、マップは自動的に任意の方向にスクロールします。

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

アクティビティ:

@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

私はベッドに行かなければならない、それは機能コードからです。だから実際にテストするためにレイアウトデザインを変更しないでください。必要に応じてコメントを残してください。しかし、しばらくは戻っていません。 –

+0

ありがとう、私は試してみましょう。誤解を避けるために:NestedScrollViewが必要なのは、コンテンツが地図ではなく大きすぎるためです。私はそれをスクロールするとアクティブになるMapViewを持つ通常のScrollViewを持っていたいと思います。 – Steeve

+0

さらに、アクティビティではなく、フラグメント内のマップを表示したい。 – Steeve

関連する問題