Android 手势监听之双击监听

来源:互联网 发布:模拟身份证阅读器软件 编辑:程序博客网 时间:2024/05/16 06:28

超级简单的自定义view

package yesun.app7;import android.content.Context;import android.util.AttributeSet;import android.view.GestureDetector;import android.view.MotionEvent;import android.view.View;/** * Created by wkk on 2016/9/21. */public class MyView extends View {    private GestureDetector gestureDetector;    private boolean background = false;    public MyView(Context context) {        this(context, null);    }    public MyView(Context context, AttributeSet attrs) {        super(context, attrs);        gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {            @Override            public boolean onDoubleTap(MotionEvent e) {                if (background)                    setBackgroundColor(0xffff00ff);                else setBackgroundColor(0xFF001AFF);                background = !background;                return super.onDoubleTap(e);            }        });    }    @Override    public boolean onTouchEvent(MotionEvent event) {        gestureDetector.onTouchEvent(event);        return true;    }}

xml没什么就不上了

效果图

0 0