android实现左右上下滚动
2013-03-27 23:17
387 查看
本篇文章来源于 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;
}
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;
}
相关文章推荐
- Android ScrollViewy与HorizontalScrollView实现上下左右滚动
- Android ScrollViewy与HorizontalScrollView实现上下左右滚动
- Android ScrollViewy与HorizontalScrollView实现上下左右滚动
- Android实现了复杂表格,表格内容区域可以与上下滑动、左右滚动,并且标题会跟着滚动
- android scrollview 实现上下左右滚动方法
- Android 用ScrollView和HorizontalScrollView同时实现上下、左右滚动
- android之实现上下左右翻页效果
- Android仿UC浏览器左右上下滚动功能(附源码)
- 我的Android进阶之旅------>Android自定义View来实现解析lrc歌词并同步滚动、上下拖动、缩放歌词的功能
- Android 实现上下滚动TextSwitcher
- Android仿UC浏览器左右上下滚动功能
- Android ObjectAnimator 无限循环播放,实现上下左右浮动效果
- Android ScrollView HorizontalScrollView 实现全方向(上下左右)反弹效果
- Android 自定义RadioButton 实现文字上下左右方向的图片大小设置
- Android中使用kotlin实现多行文本的上下滚动播放
- Android_RecyclerView实现上下滚动广告条实例(带图片)
- Android 自定义View 实现手势监听,左右滑动,上下滑动
- Android仿UC浏览器左右上下滚动功能(附源码)
- ViewGroup实现可以上下、左右滚动跑马灯效果
- iscroll实现上下左右滚动的方法