android中MotionEvent.ACTION_CANCEL事件如何被触发?
16lz
2021-12-04
对于这个问题,android文档的说明很简短,想看明白很难。国外一网页说的还比较详细,写在这里分享给大家:
原文是这样的:
You receive this when a parent takes possession of the motion, forexample when the user has dragged enough across a list view or scrollview that it will start scrolling instead of letting you press thebuttons inside of it.
意思是这样的:
当你的手指(或者其它)移动屏幕的时候会触发这个事件,比如当你的手指在屏幕上拖动一个listView或者一个ScrollView而不是去按上面的按钮时会触发这个事件。
在设计设置页面的滑动开关时,如果不监听ACTION_CANCEL,在滑动到中间时,如果你手指上下移动,就是移动到开关控件之外,则此时会触发ACTION_CANCEL,而不是ACTION_UP,造成开关的按钮停顿在中间位置。
意思就是,当用户保持按下操作,并从你的控件转移到外层控件时,会触发ACTION_CANCEL,建议进行处理~
当前的手势被中断,不会再接收到关于它的记录。
推荐将这个事件作为 ACTION_UP 来看待,但是要区别于普通的 ACTION_UP
话说回来,平常还真碰不到这个事件,习惯上就直接当 ACTION_UP 处理了就
更多相关文章
- Android点击事件的四种写法
- android根据字体大小设置控件高度
- Android(安卓)Gesture Detector
- Android(安卓)onSaveInstanceState和onRestoreInstanceState触发
- android事件处理的三种方式
- 02相对布局
- 2011.09.01(2)——— android 处理双击事件
- Android(安卓)自定义View measure模板
- android中文api(79)——Gallery