- class ZoomGesture extends GestureDetector.SimpleOnGestureListener {//单手指操作
- @Override //双击
- public boolean onDoubleTap(MotionEvent e) {
- System.out.println("--onDoubleTap---");
- return true;
- }
- @Override
- public boolean onDoubleTapEvent(MotionEvent e) {
- System.out.println("--onDoubleTapEvent---");
- return super.onDoubleTapEvent(e);
- }
- }
- //SimpleOnScaleGestureListener implements OnScaleGestureListener
- class ScaleGesture extends ScaleGestureDetector.SimpleOnScaleGestureListener {//双手指操作
- @Override
- public boolean onScale(ScaleGestureDetector detector) {
- detector.getCurrentSpan();//两点间的距离跨度
- detector.getCurrentSpanX();//两点间的x距离
- detector.getCurrentSpanY();//两点间的y距离
- detector.getFocusX(); //
- detector.getFocusY(); //
- detector.getPreviousSpan(); //上次
- detector.getPreviousSpanX();//上次
- detector.getPreviousSpanY();//上次
- detector.getEventTime(); //当前事件的事件
- detector.getTimeDelta(); //两次事件间的时间差
- detector.getScaleFactor(); //与上次事件相比,得到的比例因子
- return true;
- }
- }
创建手势探测器
[java] view
plaincopyprint?
- private GestureDetector gestureDetector; //手势探测器
- private ScaleGestureDetector scaleGestureDetector;//比率手势探测器
- ...
- gestureDetector = new GestureDetector(context, new ZoomGesture());
- scaleGestureDetector = new ScaleGestureDetector(context, new ScaleGesture());
- public boolean onTouchEvent(MotionEvent event) {
- //单点
- gestureDetector.onTouchEvent(event);
- //双点
- scaleGestureDetector.onTouchEvent(event);
- return true;
- }
时间: 2024-11-05 06:25:03