Instead of applying the GestureListener to individual views, set the containing view's GestureListener (e.g. LinearLayout or RelativeLayout). This should then work for all the views inside the container.
On 28 May 2012 07:47, Fencer04 <fence...@gmail.com> wrote: > I have swiping working to some extent but I have a series of textviews and > spinners that are on the screen and it seems like if I don't swipe straight > across one of them and go just a little across two of them it doesn't pick > it up that well. In general I don't think that it is picking up the swipe > as > good as what happens on the iPhone and I was wondering if anyone could > critique my code and help me optimize it. > > I'm initializing the GesureDectector and GestureListener. Here is the > GestureListener class: > public class GestureListener : Java.Lang.Object, > GestureDetector.IOnGestureListener > { > private static int SWIPE_MAX_OFF_PATH = 250; > private static int SWIPE_MIN_DISTANCE = 50; > private static int SWIPE_THRESHOLD_VELOCITY = 200; > private View view; > private Activity act; > > public GestureListener(View _view, Activity _act) > { > view = _view; > act = _act; > } > > public bool OnDown( MotionEvent e ) > { > return true; > } > > public bool OnFling( MotionEvent e1, MotionEvent e2, > float velocityX, > float velocityY ) > { > if ( Math.Abs( e1.GetY() - e2.GetY() ) > > SWIPE_MAX_OFF_PATH ){ > return false; > } > if ( e1.GetX() - e2.GetX() > > SWIPE_MIN_DISTANCE && Math.Abs( velocityX ) > > SWIPE_THRESHOLD_VELOCITY ){ > HandleLeft(); > }else if ( e2.GetX() - e1.GetX() > > SWIPE_MIN_DISTANCE && Math.Abs( > velocityX ) > SWIPE_THRESHOLD_VELOCITY ){ > HandleRight(); > } > return false; > } > > public void OnLongPress( MotionEvent e ) > { > > } > > public bool OnScroll( MotionEvent e1, MotionEvent e2, > float distanceX, > float distanceY ) > { > return true; > } > > public void OnShowPress( MotionEvent e ) > { > > } > > public bool OnSingleTapUp( MotionEvent e ) > { > return true; > } > > private void HandleLeft(){ > Male currActivity = (Male)act; > currActivity.GetStrings("Female"); > } > > private void HandleRight(){ > Male currActivity = (Male)act; > currActivity.GetStrings("Results"); > } > } > > I am using this for my OnTouch Event: > public bool OnTouch(View v, MotionEvent e){ > bool handled = false; > > if(flingDetector != null){ > handled = flingDetector.OnTouchEvent(e); > } > > if(v.GetType() == typeof(Spinner)){ > return !handled; > }else{ > return handled; > } > } > > Any help would be greatly appreciated. > > -- > View this message in context: > http://mono-for-android.1047100.n5.nabble.com/Swiping-like-iPhone-tp5710057.html > Sent from the Mono for Android mailing list archive at Nabble.com. > _______________________________________________ > Monodroid mailing list > Monodroid@lists.ximian.com > > UNSUBSCRIBE INFORMATION: > http://lists.ximian.com/mailman/listinfo/monodroid >
_______________________________________________ Monodroid mailing list Monodroid@lists.ximian.com UNSUBSCRIBE INFORMATION: http://lists.ximian.com/mailman/listinfo/monodroid