android 添加左右滑屏手势

来源:互联网 发布:mac玩qq游戏大厅 编辑:程序博客网 时间:2024/06/07 17:13


今天要在自己的项目中添加左右滑动,实现日期的加减(原来已经做了加减按键)。滑动在一个中间的layout中进行


思路:添加左右划屏幕判断,得到判断后模拟加减按键按下。

模拟按键按下用 mbotton.performClick(); 方法

划屏幕方法  使用 GestureDetector 手势监测类。


实现:


实现接口:OnTouchListener, OnGestureListener


创建:private GestureDetector mGestureDetector; 

实例化:new GestureDetector(this, this); //第一个this 是指该activity 的context  第二个this 是本地实现了OnGestureListener listener 的接口

重写接口:自动添加以下的几个函数,只要重写其中的

public boolean onTouch(View v, MotionEvent event)

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {





note: 在中间的layout中滑动所以  要打开该布局的 android:longClickable="true" 

实现参考:
http://www.2cto.com/kf/201110/109480.html

http://blog.csdn.net/chaijun0613/article/details/6397495



0 0
原创粉丝点击