Need Help Putting MapView inside ScrollView

3216
1
Jump to solution
05-09-2014 08:04 AM
JosephDwyer
New Contributor II
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.
0 Kudos
1 Solution

Accepted Solutions
JosephDwyer
New Contributor II
I was able to figure out a solution for inserting a MapView into a ScrollView and get the map to scroll properly.

Here is the solution I came up with:

Put this in the onCreate:
MyTouchListener tl = new MyTouchListener(this, mMapView);   mMapView.setOnTouchListener(tl);


Then I created a class that extended MapOnTouchListener.

class MyTouchListener extends MapOnTouchListener{   ScrollView sv;   public MyTouchListener(Context c, MapView m){    super(c, m);   }                    // gets the touch event for the MapView   public boolean onTouch(View v, MotionEvent event){    sv = (ScrollView) findViewById(R.id.scrollview);                         int action = event.getAction();    switch(action){    case MotionEvent.ACTION_DOWN:     // Disallow your scrollview id to intercept the touch event                                 sv.requestDisallowInterceptTouchEvent(true);     break;         case MotionEvent.ACTION_UP:     // Gives touch control back to the ScrollView                                 sv.requestDisallowInterceptTouchEvent(false);     break;    }        super.onTouch(v, event);    return true;   }        }

View solution in original post

0 Kudos
1 Reply
JosephDwyer
New Contributor II
I was able to figure out a solution for inserting a MapView into a ScrollView and get the map to scroll properly.

Here is the solution I came up with:

Put this in the onCreate:
MyTouchListener tl = new MyTouchListener(this, mMapView);   mMapView.setOnTouchListener(tl);


Then I created a class that extended MapOnTouchListener.

class MyTouchListener extends MapOnTouchListener{   ScrollView sv;   public MyTouchListener(Context c, MapView m){    super(c, m);   }                    // gets the touch event for the MapView   public boolean onTouch(View v, MotionEvent event){    sv = (ScrollView) findViewById(R.id.scrollview);                         int action = event.getAction();    switch(action){    case MotionEvent.ACTION_DOWN:     // Disallow your scrollview id to intercept the touch event                                 sv.requestDisallowInterceptTouchEvent(true);     break;         case MotionEvent.ACTION_UP:     // Gives touch control back to the ScrollView                                 sv.requestDisallowInterceptTouchEvent(false);     break;    }        super.onTouch(v, event);    return true;   }        }
0 Kudos