8

I have a horizontal scroll view that contains a hierarchy of viewgroups and then finally a google map. My problem is that the HSV is catching the left-right drag that's meant for the map. I've tried

    hsv.requestDisallowInterceptTouchEvent(true);

and even

    mapView.getParent().requestDisallowInterceptTouchEvent(true);

but to no avail. Is there anything I'm doing wrong here? Or can you suggest another solution?

I think this should have been my original question: How do I implement the solution posted here Mapview inside a ScrollView. Specifically, where do I put the code?

Community
  • 1
  • 1
user1923613
  • 626
  • 5
  • 11
  • 31
  • Checkout another working solution : https://stackoverflow.com/a/17317176/989418 – Abed Putra Jun 13 '17 at 00:36
  • Nothing new to other answers but I've just created a Gist on how I solved this: https://gist.github.com/Sottti/890daaeead1bd4784dfce7066a9011aa – Sotti Jun 25 '17 at 10:28

4 Answers4

11

It seems you on the right way, but you should call requestDisallowInterceptTouchEvent(true) method on every touch event (see docs). Try this solution

Updated:

Try this out:

final HorizontalScrollView hsv = ...
final MapView mapView = ...

mapView.setOnTouchListener(new OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_MOVE:
                hsv.requestDisallowInterceptTouchEvent(true);
                break;
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL:
                hsv.requestDisallowInterceptTouchEvent(false);
                break;
        }
        return mapView.onTouchEvent(event);
    }
});
Community
  • 1
  • 1
Alex Vasilkov
  • 6,215
  • 4
  • 23
  • 16
  • Can you help me out a bit more, please? Another problem I have is that I don't know where in the project I should put the code. I've read so many solutions to this but I really don't know where to put the code I've seen. – user1923613 Dec 25 '12 at 12:14
  • This is not working for me, the event is never called. – Loenix Sep 06 '16 at 07:36
4

For google map v2, follow the solution is this tutorial

Lorensius W. L. T
  • 1,734
  • 4
  • 19
  • 31
1

You have to create custom MapView. Follow the code snippet provided below

public class AppMapView extends MapView {

    public AppMapView(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 XML follow code below:

<com.tech.linez.brixlanepassenger.custom_views.AppMapView
   android:id="@+id/map_ride_route"
   android:layout_width="match_parent"
   android:layout_height="220dp"
   android:layout_margin="10dp"/>
Hantash Nadeem
  • 458
  • 6
  • 10
-1

try to override the onTouch of the map and always return true from it.

Rotem
  • 1,472
  • 2
  • 11
  • 18