kotlin 垂直滚动
Build a responsive UI that shows or hides the toolbar in response to user clicks whilst allowing undisturbed user scrolling.
构建一个响应式UI,以响应用户单击来显示或隐藏工具栏,同时允许用户不受干扰地滚动。
Kotlin has a fantastic ability to detect user gestures on Android systems. This is important for creating smooth, functional user interfaces that respond in a consistent and intuitive way. However, it can sometimes be difficult to differentiate between similar user actions. For example, when a user scrolls down a window of text this is detected as both a click and a scroll activity. This article will look at how to detect whether a user is clicking the screen, or whether they are scrolling, so that the toolbar can be toggled by user clicks but remain hidden whilst the user scrolls.
Kotlin具有出色的检测Android系统上用户手势的功能。 这对于创建以一致且直观的方式响应的流畅,功能强大的用户界面非常重要。 但是,有时可能很难区分相似的用户操作。 例如,当用户向下滚动文本窗口时,会将其检测为单击和滚动活动。 本文将研究如何检测用户是否正在单击屏幕或用户是否正在滚动,以便可以通过用户单击来切换工具栏,但在用户滚动时仍保持隐藏状态。
The screenshots above show the toolbar being displayed and hidden. We would like to toggle this behaviour in response to a user click, whilst allowing the user to scroll down the text without displaying the toolbar. To do this we need to follow a few steps:
上面的屏幕截图显示了正在显示和隐藏的工具栏。 我们希望响应用户单击来切换此行为,同时允许用户向下滚动文本而不显示工具栏。 为此,我们需要执行一些步骤:
- Set a listener to detect when a user is touching the ScrollView which contains the text 设置一个侦听器以检测用户何时触摸了包含文本的ScrollView
- Identify whether the user is clicking the screen or scrolling up/down
<