android fragment怎么监听上下滑动
1个回答
2016-09-11
展开全部
view 或者 activity 实现 OnGestureListener 接口。
在 onScroll 方法中实现上下滑动:
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;
}
在 onScroll 方法中实现上下滑动:
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;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询