美文网首页
Android 事件

Android 事件

作者: FrankFan | 来源:发表于2018-05-30 00:43 被阅读23次

    记 学习使用Android 中事件的疑惑点
    实现 拖拽有两个方式,一个是继承 onTouch ,处理 MotionEvent,一个是 使用 ViewDragerHelper。
    使用 ViewDragerHelper 更轻松点。

    MotionEvent.getAction() 与 MotionEvent.getActionMasked() 的区别

    看到 ViewDragerHelper 中处理 action 时使用的是 getActionMasked()getActionMasked()getAction

    https://stackoverflow.com/a/18284365
    getAction() returns a pointer id and an event (i.e., up, down, move) information.
    getActionMasked() returns just an event (i.e., up, down, move) information. Other info is masked out.
    For example:
    getAction() returns 0x0105.
    getActionMasked() will return 0x0005, which is 0x0105 && ACTION_MASK.
    1 . The value of ACTION_MASK is 0xFF. It masks the following actions.
    * ACTION_DOWN 0, UP 1, MOVE 2
    * ACTION_POINTER_DOWN 5, UP 6
    2 . The value of ACTION_POINTER_ID_MASK is 0xFF00. It masked the pointer ID from following deprecated constants.
    * ACTION_POINTER_1_DOWN 0x0005
    * ACTION_POINTER_2_DOWN 0x0105
    * ACTION_POINTER_3_DOWN 0x0205

    如果关心第二根手指和第三根手指可以用 getAction,其他的情况可以使用 getActionMasked()
    ACTION_POINTER_X_DOWN 最多支持 同时三指触控,被废弃了。如果需要同时处理更多触控,可以使用下面的方法,可以支持到同时检测 10 指。

    event.getPointerId(event.getActionIndex())
    

    scrollBy(x,y) scrollTo(x,y) setTranslationX(x,y)

    scrollXX 移动的是 View 中的内容
    setTranslationX 移动的是 View

    相关文章

      网友评论

          本文标题:Android 事件

          本文链接:https://www.haomeiwen.com/subject/blszcftx.html