android - 无法在android中使用滚动条滚动
问题描述
我试图实现 scrollView 并使用滚动条滚动。但是,它不起作用。
这是整个 xml 文件。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".ScrollingActivity">
<ScrollView
android:id="@+id/scroll"
android:layout_width="wrap_content"
android:scrollbars="vertical"
android:scrollbarThumbVertical="@color/teal_200"
android:scrollbarSize="20dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/large_text"/>
</ScrollView>
</LinearLayout>
java是默认文件。
主要问题
滚动条出现并且可以被用户看到。ScrollBar 也会改变位置。但是,当用户想要使用滚动条滚动时,滚动条没有响应。就像我们无法触摸滚动条一样,而是选择了 textView 将被滑动。
我的研究
在此之前,我确实尝试过实现 GestureDetecter 并浏览了几个链接和谷歌。
这些只是与我的问题最相关的两个链接。所以,我也尝试实现 customScrollView 。这导致应用程序崩溃。也使用了已弃用的 api。所以,我没有费心去解决这个问题。相反,我专注于替换该 api 并使该类正常工作。但是,不幸的是,即使我得到了替换它也不起作用。我跳过了该文件,因为它太长了。
解决方案
您无需使用ScrollBar
尝试是
在你XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".ScrollingActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars = "vertical"
android:text="@string/large_text"/>
</LinearLayout>
在你的java中
yourtextview.setMovementMethod(new ScrollingMovementMethod());
推荐阅读
- jquery - 我有带有 ajax 和 jquery 的喜欢按钮的问题
- c# - 如果语句不适用于某些输入
- pdf - 我在 gswin64c sDEVICE=pdfwrite 中做错了吗?
- tensorflow - Linux VM 上的 Google Cloud Deep Learning 引发未知 Cuda 错误
- node.js - 从在不同路径中工作的主函数调用辅助函数 [Node/express]
- r - 使用 TFBSTools 编写一个用于搜索 TF 的 for 循环
- java - Java netty websocket 实现
- azure - Azure Web App 部署失败,无法读取未定义的属性“updateStartupCommandAndRuntimeStack”
- javascript - 从javascript中的对象中选择至少有一位数字的项目
- spring-boot - 将 Spring WebFlux Publisher 放入模型中,是好是坏?