Handling Touch Events In Surfaceview Over Maps Api V2
I'm having issues in creating event handler that will be triggered while user moves the map around. There is a OnCameraChangeListener, but it is triggered after map moving stops.
Solution 1:
I have implemented some other solution to solve this problem. What I did - is I placed my GoogleMap inside custom RelativeLayout.
After that onInterceptTouchEvent
callback works like a charm and underlying map receives touch events as expected
here is my xml:
<com.my.package.name.map.MapRelativeLayout
android:id="@+id/map_root_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
</com.my.package.name.map.MapRelativeLayout>
And custom relative layout:
package com.my.package.name.map;
import android.content.Context;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.widget.RelativeLayout;
publicclassMapRelativeLayoutextendsRelativeLayout
{
private GestureDetector gestureDetector;
publicMapRelativeLayout(Context context, AttributeSet attrs)
{
super(context, attrs);
gestureDetector = newGestureDetector(context, newGestureListener());
}
@OverridepublicbooleanonInterceptTouchEvent(MotionEvent ev)
{
gestureDetector.onTouchEvent(ev);
returnfalse;
}
privateclassGestureListenerextendsGestureDetector.SimpleOnGestureListener {
@OverridepublicbooleanonDown(MotionEvent e) {
returntrue;
}
@OverridepublicbooleanonDoubleTap(MotionEvent e) {
returnfalse;
}
@OverridepublicbooleanonFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY)
{
returnfalse;
}
@OverridepublicbooleanonScroll(MotionEvent e1, MotionEvent e2,
float distanceX, float distanceY)
{
//do whatever you want herereturnfalse;
}
}
}
Solution 2:
From: Android ListView: overriding causes scrolling do not executed
Have you tried calling
super.onTouchEvent(event)
in youronTouchEvent
method?Edit - I think you want to return
false
as well in youronScroll
method.Then your
onTouchEvent
method should be:
@OverridepublicbooleanonTouchEvent(MotionEvent event) { if (gestureDetector.onTouchEvent(event)) { returntrue; } returnsuper.onTouchEvent(event); }
Other possible helpful links:
Post a Comment for "Handling Touch Events In Surfaceview Over Maps Api V2"