在 OnTouch 中返回真假?

Returning true and false in OnTouch?(在 OnTouch 中返回真假?)
本文介绍了在 OnTouch 中返回真假?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在 OnTouchListeneronTouch() 中返回 truefalse 有关系吗?在此示例中,我看不出返回 truefalse 之间有任何区别:Android 滑动列表

Does it matter if i return true or false in onTouch() of an OnTouchListener? I can't see any difference between returning true or false in this example: Android Swipe on List

推荐答案

返回值决定你是否消费了触摸事件.

The return value determines if you consumed the touch event.

换句话说,true 意味着这个触摸事件对你很感兴趣,并且所有后续调用这个触摸事件,如 ACTION_MOVEACTION_UP将交付给您.

In other words true means that this touch event is interesting to you and all follow up calls of this touch event like ACTION_MOVE or ACTION_UP will be delivered to you.

如果您返回 false,则触摸事件将被传递到视图层次结构中更靠前的下一个 View,您将不会收到任何后续调用.触摸事件将继续向上传递到视图层次结构,直到有人使用它.

If you return false than the touch event will be passed to the next View further up in the view hierarchy and you will receive no follow up calls. The touch event will continue to be passed further up the view hierarchy until someone consumes it.

如果您有任何其他问题,请随时提问!

If you have any further questions please feel free to ask!

这篇关于在 OnTouch 中返回真假?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)