美文网首页
android ontouch onclick

android ontouch onclick

作者: 162f127842fc | 来源:发表于2017-08-21 12:00 被阅读0次

android ontouch onclick 冲突解决:设置touch返回值为flase


mMouseview.setOnClickListener(new MouseClick());
mMouseview.setOnTouchListener(new MouseTouch());


   class MouseClick  implements View.OnClickListener{
    @Override
    public void onClick(View v) {
                    if (Math.abs(mCurx - mStartx) < 5 && Math.abs(mCurx - mStartx) < 5) { }
    }
}

@Override
public boolean onMouseTouch(View v, MotionEvent event, int index) {

    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        mStartx = (int) (event.getX());
        mStarty = (int) (event.getY());
        mCurx = mStartx;
        mCury = mStarty;
        mPrex = mStartx;
        mPrey = mStarty;
        mMouseview.invalidate();
    } else if (event.getAction() == MotionEvent.ACTION_UP) {
        mCurx = (int) (event.getX());
        mCury = (int) (event.getY());
    } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
        mCurx = (int) (event.getX());
        mCury = (int) (event.getY());
        int offsetx = mCurx - mPrex;
        int offsety = mCury - mPrey;
        if (Math.abs(offsetx) > 0 || Math.abs(offsety) > 0) {
            mPrex = mCurx;
            mPrey = mCury;
            if (mProjectionMouseService == null) {
                return false;
            }
       
        mMouseview.invalidate();
    }

    return false;
}

相关文章

网友评论

      本文标题:android ontouch onclick

      本文链接:https://www.haomeiwen.com/subject/mcycdxtx.html