安卓的滑动事件

MotionEvent()

1.ACTION_DOWN      手指刚接触屏幕;

2.ACTION_MOVE        手指在屏幕上移动;

3.ACTION_UP             手指从屏幕上松开的一瞬间;

通过MotionEvent对象我们可以得到点击事件发生的x和y的坐标。

1.getX和getY----->返回的是相对于当前View 左上角的x  和 y的坐标

2.getRawX 和getRawY ----->返回相对于手机屏幕左上角的 x  和  y 坐标。

-----------------------------------------------------------------------------------

TouchSlop()

TouchSlop是系统所能识别出的被认为是滑动的最小距离,当手指在屏幕上滑动时,如果两次滑动之间的距离小于这个 常量,那么系统就不认为你是在进行滑动操作。

获取这个常量:ViewConfiguration.get(getContext()).getScaledTouchSlop();

意义:当我们在处理滑动时,可以利用这个常量来做一些过滤, 比如当两次滑动事件的滑动距离小于这个值,我们就可以认为未达到滑动距离的临界值,因此就可以认为它们不是滑动

可以在源码中找到这个常量的定义,在frameworks/base/core/res/res/values/config.xml文件中

mTouchSlop = res.getDimensionPixelSize(
        com.android.internal.R.dimen.config_viewConfigurationTouchSlop);
<!-- Base "touch slop" value used by ViewConfiguration as a
     movement threshold where scrolling should begin. -->
<dimen name="config_viewConfigurationTouchSlop">8dp</dimen>

  1. /**
  2. * 包含了方法和标准的常量用来设置UI的超时、大小和距离
  3. */
  4. public class ViewConfiguration {
  5. // 设定水平滚动条的宽度和垂直滚动条的高度,单位是像素px
  6. private static final int SCROLL_BAR_SIZE = 10;
  7. //定义滚动条逐渐消失的时间,单位是毫秒
  8. private static final int SCROLL_BAR_FADE_DURATION = 250;
  9. // 默认的滚动条多少秒之后消失,单位是毫秒
  10. private static final int SCROLL_BAR_DEFAULT_DELAY = 300;
  11. // 定义边缘地方褪色的长度
  12. private static final int FADING_EDGE_LENGTH = 12;
  13. //定义子控件按下状态的持续事件
  14. private static final int PRESSED_STATE_DURATION = 125;
  15. //定义一个按下状态转变成长按状态的转变时间
  16. private static final int LONG_PRESS_TIMEOUT = 500;
  17. //定义用户在按住适当按钮,弹出全局的对话框的持续时间
  18. private static final int GLOBAL_ACTIONS_KEY_TIMEOUT = 500;
  19. //定义一个touch事件中是点击事件还是一个滑动事件所需的时间,如果用户在这个时间之内滑动,那么就认为是一个点击事件
  20. private static final int TAP_TIMEOUT = 115;
  21. /**
  22. * Defines the duration in milliseconds we will wait to see if a touch event
  23. * is a jump tap. If the user does not complete the jump tap within this interval, it is
  24. * considered to be a tap.
  25. */
  26. //定义一个touch事件时候是一个点击事件。如果用户在这个时间内没有完成这个点击,那么就认为是一个点击事件
  27. private static final int JUMP_TAP_TIMEOUT = 500;
  28. //定义双击事件的间隔时间
  29. private static final int DOUBLE_TAP_TIMEOUT = 300;
  30. //定义一个缩放控制反馈到用户界面的时间
  31. private static final int ZOOM_CONTROLS_TIMEOUT = 3000;
  32. /**
  33. * Inset in pixels to look for touchable content when the user touches the edge of the screen
  34. */
  35. private static final int EDGE_SLOP = 12;
  36. /**
  37. * Distance a touch can wander before we think the user is scrolling in pixels
  38. */
  39. private static final int TOUCH_SLOP = 16;
  40. /**
  41. * Distance a touch can wander before we think the user is attempting a paged scroll
  42. * (in dips)
  43. */
  44. private static final int PAGING_TOUCH_SLOP = TOUCH_SLOP * 2;
  45. /**
  46. * Distance between the first touch and second touch to still be considered a double tap
  47. */
  48. private static final int DOUBLE_TAP_SLOP = 100;
  49. /**
  50. * Distance a touch needs to be outside of a window's bounds for it to
  51. * count as outside for purposes of dismissing the window.
  52. */
  53. private static final int WINDOW_TOUCH_SLOP = 16;
  54. //用来初始化fling的最小速度,单位是每秒多少像素
  55. private static final int MINIMUM_FLING_VELOCITY = 50;
  56. //用来初始化fling的最大速度,单位是每秒多少像素
  57. private static final int MAXIMUM_FLING_VELOCITY = 4000;
  58. //视图绘图缓存的最大尺寸,以字节表示。在ARGB888格式下,这个尺寸应至少等于屏幕的大小
  59. @Deprecated
  60. private static final int MAXIMUM_DRAWING_CACHE_SIZE = 320 * 480 * 4; // HVGA screen, ARGB8888
  61. //flings和scrolls摩擦力度大小的系数
  62. private static float SCROLL_FRICTION = 0.015f;
  63. /**
  64. * Max distance to over scroll for edge effects
  65. */
  66. private static final int OVERSCROLL_DISTANCE = 0;
  67. /**
  68. * Max distance to over fling for edge effects
  69. */
  70. private static final int OVERFLING_DISTANCE = 4;
  71. }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值