Map inside scrollview not scrollable

I have a map fragment inside a vertical scrollview. I want it to be scrollable. but it is not working. I have tried adding a transparent image and also the custom Scrollview from these answers: how to set google map fragment inside scroll view

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

My layout structure:

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

Please suggest some solution. I am trying everything on Marshmallow.

you can scroll google map inside scrollview. see below link i describe how to scroll map inside scrollview in android: http://newtech4you4ever.blogspot.in/2016/08/scroll-googlemap-in-scrollview-android.html

how to set google map fragment inside scroll view, I want to set a Google map fragment inside vertical ScrollView , when I do the map does not zoom vertically, how can I override the touch event listener on� Technically, placing a map view inside a ScrollView layout container can make the map becoming difficult to scroll. This is because the scrollable layout container will intercept the touch event so the map will lose the touch event, making it difficult to scroll or pan. This happens either on Android Map V2 or the previous versions.

You can give a try on the below code and see if it works for you.

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

Now in XML file

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

How to Make Android Map V2 Scrollable Inside a ScrollView Layout, Placing a map inside a ScrollView can make the map becoming difficult to scroll. The workaround is to make a custom class to override its� I've 4 FlatLists with maxHeight set to 200 inside a ScrollView. <ScrollView> <FlatList/> <FlatList/> <FlatList/> <FlatList/> </ScrollView> and when I try to scroll a FlatList, it doesn't scroll but the ScrollView scrolls.

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

In Your activity/fragment, add the following code in onCreate/onViewCreated

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

& your layout as this

<fragment
        android:id="@+id/googleMap"
        class="com.yourpackagename.MySupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

How to solve scrolling issue in Google Maps API v2 , // Disallow ScrollView to intercept touch events. svRestoDetail. requestDisallowInterceptTouchEvent(true);. // Disable touch on transparent view. I've placed a map inside a StackLayout inside a ScrollView (using xaml), and now when I try to move around the map, I activate the ScrollView's scroll instead. How do I resolve this? Note: I'm very new, so I'd appreciate as detailed an explanation as possible.

Can't use google_maps_flutter inside of a scrolling widget � Issue , If you put a Google Map inside of a scrolling widget, the widget scrolls, and the map does not. The map should scroll, not the widget. Or at least� Avoid recycler view inside Scroll view, because scroll view give its child infinite space. This causes recycler view having wrap_content as height to measure infinitely in vertical direction (till the last item of recycler view). Instead of using recycler view inside scroll view, use only recycler view with different item types.

Google Maps API v2 SupportMapFragment inside ScrollView, Google Maps API v2 SupportMapFragment inside ScrollView - users cannot scroll the map vertically. I am trying to put a Google map inside a scroll view, so that� But even though scrolling doesn't work in the editor, it works on devices. (I have made several scrolling COnstraintLayouts, so I have tested it) Note. Regarding your code. The ScrollView is missing a closing tag, I don't know if it is the case in the file or if it is a copy-paste miss, but you may want to look at it.

When set, the scroll view will adjust the scroll position so that the first child that is currently visible and at or beyond minIndexForVisible will not change position. This is useful for lists that are loading content in both directions, e.g. a chat thread, where new messages coming in might otherwise cause the scroll position to jump.

Comments
  • suggest you try NestedScrollView instead - they added some nice enhancements with "nested scrolling" as the name suggests
  • I tried it, it throws null pointer exception in the custom Class. public void setListener(OnTouchListener listener) { mListener = listener; } This method shows unused and hence null mListener
  • can you create interface OnTouchListener?
  • you have already created it.. so yes the interface is there in the code
  • i change MainActivity Code. I change declaration of GoogleMap.Please check it.
  • Now it worked, thank you so much! by the way change the variable names in the updated code of your blog..