Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android DragGestureDetector可检测左侧、右侧、顶部和底部_Android_Gesturedetector - Fatal编程技术网

Android DragGestureDetector可检测左侧、右侧、顶部和底部

Android DragGestureDetector可检测左侧、右侧、顶部和底部,android,gesturedetector,Android,Gesturedetector,//向下滑动->向右然后向下滑动 //向右滑动->向右然后向下滑动 //向左轻扫->向左轻扫 //向上轻扫->向左,然后向上轻扫 公共类DragGestureDetector{ 公共静态字符串DEBUG_TAG=“DragGestureDetector”; 私人手势检测器Compat mGestureDetector; 私人DragListener mListener; 私有布尔值mStarted=false; 私人活动MoriginaleEvent; 浮点x1,x2; 浮动y1,y2; 公共接

//向下滑动->向右然后向下滑动
//向右滑动->向右然后向下滑动
//向左轻扫->向左轻扫
//向上轻扫->向左,然后向上轻扫
公共类DragGestureDetector{
公共静态字符串DEBUG_TAG=“DragGestureDetector”;
私人手势检测器Compat mGestureDetector;
私人DragListener mListener;
私有布尔值mStarted=false;
私人活动MoriginaleEvent;
浮点x1,x2;
浮动y1,y2;
公共接口DragListener{
布尔onDragStart(运动事件e1、运动事件e2、浮点距离X、,
浮动距离);
布尔值onDragContinue(运动事件e1、运动事件e2、浮点距离X、,
浮动距离);
布尔onDragEnd(运动事件e1、运动事件e2);
布尔onTapUp();
}
公共DragGestureDetector(上下文,DragListener myDragListener){
mGestureDetector=new GestureDetectorCompat(上下文,new MyGestureListener());
mListener=myDragListener;
}
公共事件(MotionEvent){
mGestureDetector.onTouchEvent(事件);
int action=MotionEventCompat.getActionMasked(事件);
开关(动作){
case MotionEvent.ACTION\u UP:
如果(mStarted){
姆利斯滕纳·翁德拉根德(mOriginalEvent,事件);
}
mStarted=false;
x2=event.getX();
y2=event.getY();
if(x1x2)
{
System.out.println(“sammy_左”);
}
if(y1y2)
{
System.out.println(“sammy_UP”);
}
打破
case MotionEvent.ACTION\u DOWN:
//需要设置此选项时,快速点击将不会生成drap事件,因此
//对于案例操作,originalEvent可能为空
//这将导致空指针
MoriginaleEvent=事件;
x1=event.getX();
y1=event.getY();
打破
}
}
类MyGestureListener扩展了GestureDetector.SimpleOnGestureListener{
公共布尔onScroll(MotionEvent e1、MotionEvent e2、浮点距离X、,
浮动距离){
if(mListener==null)返回true;
如果(!mStarted){
mListener.onDragStart(e1,e2,distanceX,distanceY);
mStarted=true;
}
否则{
mListener.onDragContinue(e1、e2、distanceX、distanceY);
}
MoriginaleEvent=e1;
返回true;
}
@凌驾
公共布尔onSingleTapUp(运动事件e){
返回mListener.onTapUp();
}
}

}
有关您的问题的答案,请参阅下面的链接