Android开发之手势滑动(滑动手势监听)实现方法

/** * 设置上下滑动作监听器 * @author jczmdeveloper */ private void setG

    /**
     * 设置上下滑动作监听器
     * @author jczmdeveloper
     */
    private void setGestureListener(){
        myView.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                // TODO Auto-generated method stub
                switch (event.getAction()) {

                case MotionEvent.ACTION_DOWN:
                    mPosX = event.getX();
                    mPosY = event.getY();
                    break;
                case MotionEvent.ACTION_MOVE:
                    mCurPosX = event.getX();
                    mCurPosY = event.getY();

                    break;
                case MotionEvent.ACTION_UP:
                    if (mCurPosY - mPosY > 0
                            && (Math.abs(mCurPosY - mPosY) > 25)) {
                        //向下滑動
                        
                    } else if (mCurPosY - mPosY < 0
                            && (Math.abs(mCurPosY - mPosY) > 25)) {
                        //向上滑动
                        collapse();
                    }
                    
                    break;
                }
                return true;
            }

        });
    }

发表评论

登录 后才能评论