android屏幕监控上下左右滑动
2012-12-04 23:08
489 查看
简单写一下,view 或者 activity 实现 OnGestureListener 接口。
在 onFling方法中实现左右滑动:
[java] view
plaincopy
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
float y1 = e1.getY(), y2 = e2.getY();
if (y1 -y2 > 120) {
if (mDirection != SOUTH) {
mNextDirection = NORTH;
}
Log.d(this.getClass().getName(), "To UP" + "(" + y1
+ "," + y2 + ")");
return (true);
} else if (y1 - y2 < -120) {
if (mDirection != NORTH) {
mNextDirection = SOUTH;
}
Log.d(this.getClass().getName(), "To Down" + "(" + y1
+ "," + y2 + ")");
return (true);
}
return false;
}
在 onScroll 方法中实现上下滑动:
[java] view
plaincopy
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
Log.d("Fling", "Fling Happened!");
float x1 = e1.getX(), x2 = e2.getX();
if (x1 -x2 > 120) {
if (mDirection != EAST) {
mNextDirection = WEST;
}
Log.d(this.getClass().getName(), "To LEFT" + "(" + x1
+ "," + x2 + ")");
return (true);
} else if (x1 - x2 < -120) {
if (mDirection != WEST) {
mNextDirection = EAST;
}
Log.d(this.getClass().getName(), "To Right" + "(" + x1
+ "," + x2 + ")");
return (true);
}
return false;
}
在 onFling方法中实现左右滑动:
[java] view
plaincopy
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
float y1 = e1.getY(), y2 = e2.getY();
if (y1 -y2 > 120) {
if (mDirection != SOUTH) {
mNextDirection = NORTH;
}
Log.d(this.getClass().getName(), "To UP" + "(" + y1
+ "," + y2 + ")");
return (true);
} else if (y1 - y2 < -120) {
if (mDirection != NORTH) {
mNextDirection = SOUTH;
}
Log.d(this.getClass().getName(), "To Down" + "(" + y1
+ "," + y2 + ")");
return (true);
}
return false;
}
在 onScroll 方法中实现上下滑动:
[java] view
plaincopy
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
Log.d("Fling", "Fling Happened!");
float x1 = e1.getX(), x2 = e2.getX();
if (x1 -x2 > 120) {
if (mDirection != EAST) {
mNextDirection = WEST;
}
Log.d(this.getClass().getName(), "To LEFT" + "(" + x1
+ "," + x2 + ")");
return (true);
} else if (x1 - x2 < -120) {
if (mDirection != WEST) {
mNextDirection = EAST;
}
Log.d(this.getClass().getName(), "To Right" + "(" + x1
+ "," + x2 + ")");
return (true);
}
return false;
}
相关文章推荐
- android屏幕监控上下左右滑动
- android屏幕监控上下左右滑动
- android屏幕监控上下左右滑动
- android屏幕监控上下左右滑动
- Android 自定义View 实现手势监听,左右滑动,上下滑动
- android开发步步为营之71:CoordinatorLayout+AppBarLayout+RecyclerView+ViewPager打造可上下左右滑动的App主框架
- Android 用onTouchEvent判断上下左右滑动
- Android图片上下左右滑动特效--Recycker实现
- android GestureDetector简单手势检测(左右滑动、上下滑动)
- Android OnGestureListener用法 识别用户手势 上下左右滑动
- Android ScrollView与ViewPager滑动上下左右冲突
- Android手势识别——上下左右滑动、屏幕上下左右中区域处理
- Android监测手指上下左右滑动屏幕
- Android——滑动监听RecyclerView线性流+左右划删除+上下移动
- android中使用Activity实现监听手指上下左右滑动
- android 图片 上下左右滑动,能放大放小
- Android监测手指上下左右滑动屏幕
- Android开发ScrollView上下左右滑动事件冲突整理一(根据事件)
- Android自定义左右或上下滑动翻页效果
- Android5.x:RecycleView(三):上下拖动和左右滑动删除