====如何设置手势

private GestureDetector detector;


先定义一个对象

public JiyibiMembersManagerEditDialog(Context context, int theme, RecordTag tag, MembersManagerEditCallBack mMECallBack) {
        super(context, theme);
        this.rt = tag;
        this.mCallBack = mMECallBack;
//        this.detector = new GestureDetector(getContext(), new ViewGestureListener());
    }
在初始化中为对象赋值

class ViewGestureListener implements GestureDetector.OnGestureListener {

        // 用户轻触触摸屏,由1个MotionEvent ACTION_DOWN触发

        public boolean onDown(MotionEvent e) {
            return false;
        }
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            float minMove = 120;         //最小滑动距离
            float minVelocity = 0;      //最小滑动速度
            float beginX = e1.getX();
            float endX = e2.getX();
            float beginY = e1.getY();
            float endY = e2.getY();
            if(beginX-endX>minMove&&Math.abs(velocityX)>minVelocity){   //左滑
            }else if(endX-beginX>minMove&&Math.abs(velocityX)>minVelocity){   //右滑
            }else if(beginY-endY>minMove&&Math.abs(velocityY)>minVelocity){   //上滑
//                InputMethodManager imm = (InputMethodManager)getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(addNewMember.getWindowToken(),0);
               /* InputMethodManager imm = (InputMethodManager)getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                if(imm.isActive()&&getCurrentFocus()!=null){
                    if (getCurrentFocus().getWindowToken()!=null) {
                        imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
                    }
                }*/
            }else if(endY-beginY>minMove&&Math.abs(velocityY)>minVelocity){   //下滑
            }
            return false;
        }
        // 用户长按触摸屏,由多个MotionEvent ACTION_DOWN触发
        public void onLongPress(MotionEvent e) {
        }
        // 用户按下触摸屏,并拖动,由1个MotionEvent ACTION_DOWN, 多个ACTION_MOVE触发
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
            return false;
        }
        // 用户轻触触摸屏,尚未松开或拖动,由一个1个MotionEvent ACTION_DOWN触发
        // 注意和onDown()的区别,强调的是没有松开或者拖动的状态
        public void onShowPress(MotionEvent e) {
        }
        // 用户(轻触触摸屏后)松开,由一个1个MotionEvent ACTION_UP触发
        public boolean onSingleTapUp(MotionEvent e) {
            return false;
        }
    }// end class ViewGestureListener
设置监听

listView.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        return detector.onTouchEvent(event);
    }
});
//在需要监听的TouchListener中使用自己定义的Touch

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值