示例#1
0
 public ViewScrollHelper(View view, GestureHelper gestureHelper) : base(gestureHelper)
 {
     this.View = view;
 }
 public InterceptTouchHelper(ViewGroup parent, GestureHelper gestureHelper)
 {
     this.Parent        = parent;
     this.GestureHelper = gestureHelper;
 }
示例#3
0
 public ScrollHelper(Context context) : this(GestureHelper.CreateDefault(context))
 {
 }
示例#4
0
        /// <summary>
        /// 触发触摸事件
        /// </summary>
        /// <param name="event">事件</param>
        public void OnTouchEvent(MotionEvent @event)
        {
            GestureHelper.OnTouchEvent(@event);
            VelocityTracker.AddMovement(@event);
            switch (@event.Action)
            {
            case MotionEventActions.Down:
            {
                SetStartPosition(@event.GetX(), @event.GetY());
                break;
            }

            case MotionEventActions.Move:
            {
                if (CanScroll)
                {
                    float rangeX = @event.GetX() - startTouchX;
                    float rangeY = @event.GetY() - startTouchY;
                    int   dstX   = (int)(startScrollX - rangeX);
                    int   dstY   = (int)(startScrollY - rangeY);
                    if (dstX < GetMinHorizontallyScroll)
                    {
                        dstX         = 0;
                        startTouchX  = @event.GetX();
                        startScrollX = dstX;
                    }
                    else if (dstX > GetMaxHorizontallyScroll)
                    {
                        dstX         = GetViewHorizontallyScrollSize();
                        startTouchX  = @event.GetX();
                        startScrollX = dstX;
                    }
                    if (dstY < GetMinVerticallyScroll)
                    {
                        dstY         = 0;
                        startTouchY  = @event.GetY();
                        startScrollY = dstY;
                    }
                    else if (dstY > GetMaxVerticallyScroll)
                    {
                        dstY         = GetViewVerticallyScrollSize();
                        startTouchY  = @event.GetY();
                        startScrollY = dstY;
                    }
                    ViewScrollTo(dstX, dstY);
                }
                break;
            }

            case MotionEventActions.Up:
            case MotionEventActions.Cancel:
            {
                VelocityTracker.ComputeCurrentVelocity(1000);
                if (CanScroll)
                {
                    float xv = VelocityTracker.XVelocity;
                    float yv = VelocityTracker.YVelocity;
                    ViewFling(xv, yv);
                }
                break;
            }
            }
        }
示例#5
0
 public ScrollHelper(GestureHelper gestureHelper)
 {
     this.GestureHelper   = gestureHelper;
     this.VelocityTracker = VelocityTracker.Obtain();
 }