5

我在某种程度上进行了滑动工作,但我在屏幕上有一系列文本视图和微调器,似乎如果我不直接滑动其中一个,而是稍微跨过其中两个,它不会选择它那么好。总的来说,我认为它的滑动效果不如 iPhone 上发生的那样好,我想知道是否有人可以批评我的代码并帮助我优化它。

我正在初始化 GesureDectector 和 GestureListener。这是 GestureListener 类:

    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");
        }
    }

我将它用于我的 OnTouch 事件:

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

任何帮助将不胜感激。

4

0 回答 0