====手势的使用
来源:互联网 发布:dede上传网站源码 编辑:程序博客网 时间:2024/05/01 20:18
private GestureDetector detector;
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); }});
0 0
- ====手势的使用
- 手势监测器的使用
- 手势的简单使用
- 简单的手势的使用
- android 手势 API的使用
- android 手势 API的使用
- Android 手势 API的使用
- IOS各种手势的使用
- 手势识别的简单使用
- iOS拖动手势的使用
- GestureDetector手势检测器的使用
- 手势类--GestureDetector的使用
- iOS中手势的使用
- FingerGestures手势插件的使用
- swift 中手势的使用
- gesture--Android手势的使用
- 9.6 触摸和手势:手势识别器的使用
- 手势UIGestureRecognizer 几种手势的使用实现
- C#调用C++字符集与类型对比
- SSM框架——详细整合教程(Spring+SpringMVC+MyBatis)
- QT5 下udp 编程实例
- iOS开发——单例
- LibGDX_2.1: LibGDX 应用框架(6 大系统交互接口)
- ====手势的使用
- 《疯狂JAVA讲义》——instanceof运算符
- [读书笔记] The.Way.To.Go
- c#调用JAVA提供的WebService处理日期格式
- 以POJ1061青蛙的约会为例谈扩展欧几里得算法
- iOS工程适配64-bit经验分享
- C-045.结构体指针
- 仿微信二维码的制作
- linux utils