kotlin 垂直滚动_在Android的Kotlin中检测点击或滚动

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系统上用户手势的功能。 这对于创建以一致且直观的方式响应的流畅,功能强大的用户界面非常重要。 但是,有时可能很难区分相似的用户操作。 例如,当用户向下滚动文本窗口时,会将其检测为单击和滚动活动。 本文将研究如何检测用户是否正在单击屏幕或用户是否正在滚动,以便可以通过用户单击来切换工具栏,但在用户滚动时仍保持隐藏状态。

Image for post
Image for post
Screenshots showing the toolbar in hidden and visible modes
屏幕截图显示了隐藏和可见模式下的工具栏

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:

上面的屏幕截图显示了正在显示和隐藏的工具栏。 我们希望响应用户单击来切换此行为,同时允许用户向下滚动文本而不显示工具栏。 为此,我们需要执行一些步骤:

  1. Set a listener to detect when a user is touching the ScrollView which contains the text

    设置一个侦听器以检测用户何时触摸了包含文本的ScrollView
  2. Identify whether the user is clicking the screen or scrolling up/down

    <

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值