永发信息网

android fragment怎么监听上下滑动

答案:1  悬赏:80  手机版
解决时间 2021-01-29 03:36
  • 提问者网友:寂寞撕碎了回忆
  • 2021-01-28 23:19
android fragment怎么监听上下滑动
最佳答案
  • 五星知识达人网友:梦中风几里
  • 2021-01-28 23:42
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;
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯