`
film
  • 浏览: 227581 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

android实现左右上下滚动

 
阅读更多

本篇文章来源于 Linux公社网站(www.linuxidc.com) 原文链接:http://www.linuxidc.com/Linux/2012-06/62567.htm

view 或者 activity 实现 OnGestureListener 接口
在 onFling方法中实现左右滑动:
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 方法中实现上下滑动:

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;
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics