4.30
所花时间(包括上课):1.5
打码量(行):150
博客量(篇):1
了解到知识点:学习手势检测
public class MyGestureView extends View {
private GestureDetector gestureDetector;
public MyGestureView(Context context) {
super(context);
init();
}
public MyGestureView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init();
}
private void init() {
gestureDetector = new GestureDetector(getContext(), new MyGestureListener());
setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return gestureDetector.onTouchEvent(event);
}
});
}
private class MyGestureListener extends GestureDetector.SimpleOnGestureListener {
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
// 单击事件处理逻辑
return true;
}
@Override
public void onLongPress(MotionEvent e) {
// 长按事件处理逻辑
}
@Override
public boolean onDoubleTap(MotionEvent e) {
// 双击事件处理逻辑
return true;
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
// 滑动事件处理逻辑
return true;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
// 快速滑动事件处理逻辑
return true;
}
@Override
public boolean onDown(MotionEvent e) {
// 按下事件处理逻辑
return true;
}
}
}
本文来自博客园,作者:赵千万,转载请注明原文链接:https://www.cnblogs.com/zhaoqianwan/p/18138352
千万千万赵千万