MapView inside a ScrollView?

xamarin forms map inside scrollview
map in scrollview react native
mapview'' android

I would like to have a MapView inside a ScrollView, however when I try to scroll the map, the ScrollView takes priority! Is there a way to give the MapView priority when scrolling inside the map, and the ScrollView otherwise?

Thanks!

I have had a same problem for 10 days, but I got a solution a few minutes ago!! Here is the solution. I made a custom MapView and override onTouchEvent() like this.

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

how to set google map fragment inside scroll view, scrollMap); //parent scrollview in xml, give your scrollview id value ((​WorkaroundMapFragment) Add a transparent view over the mapview fragment: 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.

A better/simpler way to do this without manipulating individual touch events. This will work if you are using MapView:

  @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        /**
         * Request all parents to relinquish the touch events
         */
        getParent().requestDisallowInterceptTouchEvent(true);
        return super.dispatchTouchEvent(ev);
    }

Full class:

public class CustomMapView extends MapView {

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

    public CustomMapView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomMapView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public CustomMapView(Context context, GoogleMapOptions options) {
        super(context, options);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        /**
         * Request all parents to relinquish the touch events
         */
        getParent().requestDisallowInterceptTouchEvent(true);
        return super.dispatchTouchEvent(ev);
    }
}

If you are using a MapFragment then you can put the fragment in a Custom View, and in the dispatchTouchEvent() make the requestDisallowInterceptTouchEvent call.

Android MapView inside ScrollView, Technically, placing a map inside a ScrollView will cause the map becoming difficult to scroll Duration: 0:27 Posted: Feb 16, 2014 The MapView appears to not work at all currently when placed inside of a ScrollView. I was setting this up inside of a ScrollView and spent a bunch of time wondering why I was getting no errors but no map was showing up. I ended up discovering that switching its parent container from a ScrollView to a regular View made the map appear with no issues.

Make your own map and use it. It works fully for me.

public class CustomMapView extends MapView {

public CustomMapView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    switch (ev.getAction()) {
    case MotionEvent.ACTION_UP:
        System.out.println("unlocked");
        this.getParent().requestDisallowInterceptTouchEvent(false);
        break;
    case MotionEvent.ACTION_DOWN:
        System.out.println("locked");
        this.getParent().requestDisallowInterceptTouchEvent(true);
        break;
    }
    return super.dispatchTouchEvent(ev);
}} 

In your layout xml,

<com.yourpackage.xxxx.utils.CustomMapView
                android:id="@+id/customMap"
                android:layout_width="match_parent"
                android:layout_height="400dp"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                />

MapView does not display inside of scrollview · Issue #997 , The MapView appears to not work at all currently when placed inside of a ScrollView. I was setting this up inside of a ScrollView and spent a  Okay I have an app that shows the map within a scrollview layout. The problem is I can pan the map left and right but when I try up and down the scrollview touch event interferes with the mapview touch event. Anyone else run into this issue if so what is a good way to override the scrollview touch event.

For those who want the whole working code . here it is

Custom map view class

public class CustomMapView extends MapView {

private ViewParent mViewParent;
public CustomMapView(Context context) {
    super(context);
}

public CustomMapView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public CustomMapView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

public CustomMapView(Context context, GoogleMapOptions options) {
    super(context, options);
}

public void setViewParent(@Nullable final ViewParent viewParent) { //any ViewGroup
    mViewParent = viewParent;
}

@Override
public boolean onInterceptTouchEvent(final MotionEvent event) {
    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            if (null == mViewParent) {
                getParent().requestDisallowInterceptTouchEvent(true);
            } else {
                mViewParent.requestDisallowInterceptTouchEvent(true);
            }
            break;
        case MotionEvent.ACTION_UP:
            if (null == mViewParent) {
                getParent().requestDisallowInterceptTouchEvent(false);
            } else {
                mViewParent.requestDisallowInterceptTouchEvent(false);
            }
            break;
        default:
            break;
    }

    return super.onInterceptTouchEvent(event);
  }
}

Activity layout xml

  <ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <location.to.your.CustomMapView
        android:id="@+id/mapView"
        android:layout_width="match_parent"
        android:layout_height="250dp"
         />

</ScrollView>

Instantiating the custom map class in your activity or fragment

       CustomMapView mapView = (CustomMapView) findViewById(R.id.mapView);

That's it enjoy

Need Help Putting MapView inside ScrollView, The problem is I can pan the map left and right but when I try up and down the scrollview touch event interferes with the mapview touch event. 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.

You can create a custom MapView like this:

public class CustomMapView extends MapView {

    private MapFragment.ControlLock mCallbackControl;

    public CustomMapView(Context context) {
        this(context, null);
    }

    public CustomMapView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CustomMapView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public CustomMapView(Context context, GoogleMapOptions options) {
        super(context, options);
    }

    public void setCallback(MapFragment.ControlLock callbackControl) {
        this.mCallbackControl = callbackControl;
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent event) {

        switch (event.getAction()) {
            case MotionEvent.ACTION_UP:
                System.out.println("unlocked");
                mCallbackControl.unlock(); /* Interface */
                break;
            case MotionEvent.ACTION_DOWN:
                System.out.println("locked");
                mCallbackControl.lock(); /* Interface */
                break;
        }

        return super.dispatchTouchEvent(event);
    }
}

How to Make Android Map V2 Scrollable Inside a ScrollView Layout, Technically, placing a map view inside a ScrollView layout container can make the map becoming difficult to scroll. This is because the  It appears that a MapView inside a vanilla ScrollView also required a fixed height. Is there a way to do this without specifying a fixed height, possibly by using flex-basis and/or flex-shrink? I circumvented this problem by using vh like so:

how to set google map fragment inside scroll view, I want to set a Google map fragment inside vertical ScrollView when I do the I override the touch event listener on MapView over the listener of ScrollView ? MapView for iOS is with greater priority than ScrollView. When you try to scroll, you scroll the map. If the content of the ScrollView should be scrolled, the user has to touch something outside th

MapView inside a Scroll View Not working : reactnative, I tried to find solutions for this on stackOverflow and tried to implement the solutions given in there(Stopping scroll view of the map view) but its still not working. Hi, i have a RecyclerView with differents layouts to show, one of them is a MapView, the map display correctly,but when i try scroll up or down the map, the "Scroll" of RecyclerView takes priority.

How to provide proper scrolling for a map inside a ScrollView , I have a problem that appears in Android: I've placed a map inside a StackLayout inside a ScrollView (using xaml), and now when I try to move  Inside Android Apk + OBB is Available to Download Now. You can enjoy playing Inside Apk anywhere you go. mapview inside scrollview android, menu inside menu

Comments
  • What's your layout? can you post a screenshot of the final layout that is rendered.
  • MapView automatically handles the scrolling....
  • I know. I have a ScrollView which contains a lot of different things, including a MapView. The problem is that when I try to scroll inside the mapview, the scrollview will override it.
  • I was also doing that in my app, but didn't get any solution so i put mapview outside the scroll view and rest of the layout in the scrollview.
  • You can use this template: <LinearLayout><LL><FL><MAP></FL></LL><LL><SV><OtherLayouy></SV></LL>. Also provide the layout_weight value to each LL(LinearLayout) According to your size.
  • @Luizje: the flashing is caused by the background colors you are using for each view. So make sure you have the outermost view using the corect bg color.
  • if it doesn't work for you, try to override the dispatchTouchEvent method instead (same implementation, just change the super call at the end). thanks.
  • @Rotem your solution worked for me. I had a com.google.android.gms.maps.MapView in a ScrollView and it didn't work with the above code. I extened this class and wrote your solution with overriding the dispatchTouchEvent method.
  • @Rotem: It works with dispatchTouchEvent. Thanks buddy.. Njoyee coding.
  • @Rotem, your comment saved my ass. Thanks dude.
  • Thank boss. Its perfectly for me.
  • This is the best answer, Thank you.
  • Nice, although requestDisallowInterceptTouchEvent is necessary for MotionEvent.ACTION_DOWN only.