android左右滑动监听,上下滑动

转至:https://www.cnblogs.com/JczmDeveloper/p/3772967.html
// 获取布局文件
LayoutInflater inflateImage = (LayoutInflater) mContext
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mAlertImageViewD = inflateImage.inflate(R.layout.alert_image, null);
// 左右滑动监听
setGestureListener();


private void setGestureListener(){
	// 是要监听的视图 mAlertImageViewD

        mAlertImageViewD.setOnTouchListener(new View.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)) {
//                            //向下滑動
//                            tiShi(mContext,"向下");
//
//                        } else if (mCurPosY - mPosY < 0
//                                && (Math.abs(mCurPosY - mPosY) > 25)) {
//                            //向上滑动
//                            tiShi(mContext,"向上");
//                        }
                        if (mCurPosX - mPosX > 0
                                && (Math.abs(mCurPosX - mPosX) > 25)) {
                            //向左滑動
//                            tiShi(mContext,"向左");
                           
                        } else if (mCurPosX - mPosX < 0
                                && (Math.abs(mCurPosX - mPosX) > 25)) {
                            //向右滑动
                            
//                            tiShi(mContext,"向右");
                         }
                        break;
                }
                return true;
            }

        });
    }

你可能感兴趣的:(android)