2016-08-29 8 views
0

私は、垂直スクロールビュー内にマップフラグメントを持っています。私はそれをスクロール可能にしたい。それは動作していません。 私は透明の画像を追加してみましたし、またこれらの答えからカスタムScrollviewている:私のレイアウト構造を how to set google map fragment inside scroll viewスクロールビューがスクロール可能でない地図

Google Maps API v2 SupportMapFragment inside ScrollView - users cannot scroll the map vertically

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/scrollView" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context=".activities.TripDetailsActivity"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#ECF0F1" 
    android:orientation="vertical"> 

    <android.support.v7.widget.CardView 
     android:id="@+id/card_map" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="10dp"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@color/colorCard" 
      android:orientation="vertical" 
      android:weightSum="12"> 

      <TextView 
       android:id="@+id/tripTxt" 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_marginLeft="20dp" 
       android:layout_marginTop="20dp" 
       android:layout_marginBottom="5dp" 
       android:layout_weight="3" 
       android:text="Trip" 
       android:textColor="@color/colorTextCard" 
       android:textSize="20sp" /> 

      <fragment 
       android:id="@+id/map" 
       android:name="com.google.android.gms.maps.SupportMapFragment" 
       android:layout_width="match_parent" 
       android:layout_height="300dp" 
       android:layout_margin="10dp" 
       tools:context="com.example.keelindemo.Activities.Map" /> 

      <TextView 
       android:id="@+id/start_point" 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_marginLeft="10dp" 
       android:layout_weight="2" 
       android:drawableLeft="@drawable/flag_start" 
       android:drawablePadding="10dp" 
       android:gravity="center_vertical" 
       android:textColor="@color/colorTextCard" /> 

      <TextView 
       android:id="@+id/end_point" 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_marginBottom="10dp" 
       android:layout_marginLeft="10dp" 
       android:layout_marginTop="10dp" 
       android:layout_weight="2" 
       android:drawableLeft="@drawable/flag_end" 
       android:drawablePadding="10dp" 
       android:gravity="center_vertical" 
       android:textColor="@color/colorTextCard" /> 

     </LinearLayout> 

    </android.support.v7.widget.CardView> 

いくつかのソリューションを提案してください。私はマシュマロのすべてを試しています。

+0

代わりに 'NestedScrollView'を試してみることをお勧めします - 彼らは名前が示すように"入れ子にされたスクロール "でいくつかの素敵な拡張を追加しました –

答えて

1

スクロールビュー内でGoogleマップをスクロールできます。 私はアンドロイドでスクロールビュー内でスクロールする方法について説明しています。 http://newtech4you4ever.blogspot.in/2016/08/scroll-googlemap-in-scrollview-android.html

+0

それはすべてのバージョンで動作していますマシュマロが含まれています。 –

+0

私はそれを試して、それはカスタムクラスでnullポインタの例外をスローします。 public void setListener(OnTouchListener listener){ mListener = listener; } このメソッドは、使用されていないヌルmListenerを表示します –

+0

インターフェイスOnTouchListenerを作成できますか? –

0

下記のコードを試してみてください。あなたの活動/フラグメントで

View customView = null; 
ScrollView scrollViewParent = null; 

scrollViewParent = (ScrollView) v.findViewById(R.id.scrollViewParent); 
customView = (View) v.findViewById(R.id.customView); 

customView.setOnTouchListener(new View.OnTouchListener() { 
    @Override 
    public boolean onTouch(View v, MotionEvent event) { 
     int action = event.getAction(); 
     switch (action) { 
     case MotionEvent.ACTION_DOWN: 
      // Disallow ScrollView to intercept touch events. 
      scrollViewParent.requestDisallowInterceptTouchEvent(true); 
      // Disable touch on transparent view 
      return false; 

     case MotionEvent.ACTION_UP: 
      // Allow ScrollView to intercept touch events. 
      scrollViewParent.requestDisallowInterceptTouchEvent(false); 
      return true; 

     case MotionEvent.ACTION_MOVE: 
      scrollViewParent.requestDisallowInterceptTouchEvent(true); 
      return false; 

     default: 
      return true; 
     } 
    } 
}); 
XMLファイルで今すぐ

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/scrollViewParent" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 
     <fragment 
      android:id="@+id/map" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      class="com.google.android.gms.maps.SupportMapFragment" /> 

     <View 
      android:id="@+id/customView" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:background="@android:color/transparent" /> 
</ScrollView> 
+0

はすでに試してみましたが動作しません –

0
public class MySupportMapFragment extends SupportMapFragment { 

    private OnTouchListener mListener; 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) { 

     View layout = super.onCreateView(inflater, parent, savedInstanceState); 
     TouchableWrapper frameLayout = new TouchableWrapper(getActivity()); 
     frameLayout.setBackgroundColor(getResources().getColor(android.R.color.transparent)); 
     ((ViewGroup) layout).addView(frameLayout, 
       new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); 

     return layout; 
    } 

    public void setListener(OnTouchListener listener) { 
     mListener = listener; 
    } 

    public interface OnTouchListener { 
     public abstract void onTouch(); 
    } 

    public class TouchableWrapper extends FrameLayout { 

     public TouchableWrapper(Context context) { 
      super(context); 
     } 

     @Override 
     public boolean dispatchTouchEvent(MotionEvent event) { 
      switch (event.getAction()) { 
       case MotionEvent.ACTION_DOWN: 
        mListener.onTouch(); 
        break; 
       case MotionEvent.ACTION_UP: 
        mListener.onTouch(); 
        break; 
      } 
      return super.dispatchTouchEvent(event); 
     } 
    } 
} 

、のonCreate /に次のコードを追加します。この

として

ScrollView nScrollView = (ScrollView) findViewById(R.id.scrollViewParent); 
      MySupportMapFragment mSupportMapFragment; 
      mSupportMapFragment = (MySupportMapFragment) getChildFragmentManager().findFragmentById(R.id.googleMap); 

      mSupportMapFragment.setListener(new MySupportMapFragment.OnTouchListener() { 
         @Override 
         public void onTouch() { 
          mScrollView.requestDisallowInterceptTouchEvent(true); 
         } 
        }); 

      if (mSupportMapFragment != null) { 
       mSupportMapFragment.getMapAsync(new OnMapReadyCallback() { 
        @Override 
        public void onMapReady(GoogleMap googleMap) { 
         if (googleMap != null) { 
          googleMap.getUiSettings().setAllGesturesEnabled(true); 
          googleMap.getUiSettings().setZoomControlsEnabled(true); 
          LatLng marker_latlng = new LatLng(lat, lon); 
          CameraPosition cameraPosition = new CameraPosition.Builder().target(marker_latlng).zoom(15.0f).build(); 
          CameraUpdate cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition); 
          googleMap.moveCamera(cameraUpdate); 
          if (latitude != null && longitude != null) { 
            googleMap.addMarker(new MarkerOptions().position(marker_latlng).title("Address")); 
} 
         } 
        } 
       }); 
      } 

&レイアウトをonViewCreated

<fragment 
     android:id="@+id/googleMap" 
     class="com.yourpackagename.MySupportMapFragment" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 
関連する問題