如何防止滚动视图在数据加载后滚动到网页视图?

2024-01-07

所以我有一个有趣的问题。尽管我没有手动或以编程方式滚动视图,但我的 WebView 会在加载其中的数据后自动滚动。

我在 viewpager 中有一个片段。当我第一次加载寻呼机时,它按预期工作并且显示所有内容。但是,一旦我“翻转页面”,数据就会加载,并且 WebView 会弹出到页面顶部,隐藏其上方的视图,这是不可取的。

有谁知道如何防止这种情况发生?

我的布局看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/background" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/article_title"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="2dp"
            android:text="Some Title"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="@color/article_title"
            android:textStyle="bold" />

        <LinearLayout
            android:id="@+id/LL_Seperator"
            android:layout_width="fill_parent"
            android:layout_height="1dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="5dp"
            android:layout_marginBottom="5dp"
            android:background="@color/text"
            android:orientation="horizontal" >
        </LinearLayout>

        <WebView
            android:id="@+id/article_content"
            android:layout_width="match_parent"
            android:layout_marginRight="10dp"
            android:layout_marginLeft="10dp"
            android:layout_height="wrap_content" />

        <TextView
            android:id="@+id/article_link"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5dp"
            android:layout_marginTop="5dp"
            android:layout_marginRight="10dp"
            android:layout_marginLeft="10dp"
            android:text="View Full Article"
            android:textColor="@color/article_title"
            android:textStyle="bold" />
    </LinearLayout>

</ScrollView>

我也没有把注意力集中在任何事情上。默认情况下,它似乎在加载后自动滚动到 WebView。我该如何防止这种情况?


我遇到了同样的问题,经过几个小时的尝试几个想法后,最终对我有用的是简单地添加descendantFocusability包含 LinearLayout 的 ScrollView 的属性,其值为blocksDescendants。在你的情况下:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:descendantFocusability="blocksDescendants" >

从那以后就没有再出现过这个问题。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何防止滚动视图在数据加载后滚动到网页视图? 的相关文章

随机推荐

  • Slick:选项列过滤

    我想做这样的事情 这是一个虚构的例子 以简化我的实际问题 def findByGender isMale Option Boolean People filter row gt row name isNotNull isMale match
  • 如何禁用编译器和 JVM 优化?

    我有这段正在测试的代码Calendar getInstance getTimeInMillis vs System currentTimeMilli long before getTimeInMilli for int i 0 i lt T
  • 从 java 代码启动和停止 Tomcat

    基于我在 Stackoverflow 和互联网上其他页面上看到的代码 我创建了一种方法来停止和启动 tomcat 此时我将在系统中运行一个进程 因为我需要清理操作系统中的内存 我使用System gc 但仍然不足以释放内存 这是代码 全球声
  • 将 UTF-8 转换为 base64 字符串

    我正在尝试转换UTF 8 to base64 string 示例 我有 abcdef UTF 8 它实际上是一个 代表 base64细绳 如何检索 abcdef base64字符串 请注意 我不想要来自的 abcdef 翻译 UTF 8 我
  • Java 8:Lambda 函数和通用通配符

    我有以下课程 class Book implement Borrowable Override public String toString Function
  • NSOperationQueue 在 iPhone 上不重用线程

    我正在使用 iPhone SDK 3 1 2 以下代码显示 NSOperationQueue 不会为每个任务重用线程 该代码在 Snow Leopard 上没有任何问题 void applicationDidFinishLaunching
  • YouTube API - 检索超过 5000 个项目

    我只想获取所有我喜欢的视频 25k 项 据我的研究表明 通过 YouTube v3 API 是不可能实现这一点的 我已经发现多个问题 issue https stackoverflow com questions 56389215 how
  • 使用 jQuery 计算两个特定行之间的表行数

    table tr td Parent 1 td tr tr class child td Child 1 td tr tr class child td Child 2 td tr tr td Parent2 td tr table 如何使
  • 将VBA中的文件路径替换为用户名

    我有一个 Excel 文件 上面写有 VBA 它从我的计算机上的文件中提取信息 Excel 文件位于网络文件夹中 我希望网络上的其他用户也能使用它 但是 我已对 VBA 上的文件路径进行了硬编码 因此 每当其他用户打开它时 它都会查找不可用
  • 如何在应用程序域之间传递事件?

    我有两个应用程序域 一个父域创建子域 在子域中 有一个MarshalByRef对象 使用 NET Remoting 进行通信 在父域中运行的对象调用远程对象的包装器作为应用程序功能的一部分 public class ScanningTask
  • 这是什么意思? (谷歌地图 API)

    我在控制台中收到此错误消息 谁能解释为什么 并且页面正在正常运行 js key MyAPIKey v 3 exp libraries places drawing geometry 32 InvalidValueError not an i
  • 将用户 ID 添加到 PhoneGap 文件上传

    我想使用 PhoneGap API 上传照片 FileTransfer 对象基本上就是我想要的 因为我想上传照片 但我想包含一些有关用户的基本信息 例如他们的用户 ID 以便我可以将其存储为他们的 我的代码如下 这基本上来自PhoneGap
  • ifstream 未打开文件

    在此函数中 我试图打开一个文件 其中包含一组我想分配给矩阵数组的字符 但是每当我运行此程序时 控制台都会显示一条错误 指出该文件未打开 另一个问题 如果我将该文件添加到我的资源文件夹中 我如何指定访问该文件而不是硬盘驱动器根目录中的文件 i
  • Keras:如何在训练和测试阶段使用 dropout?

    是否可以在 Keras 的训练和测试阶段使用 dropout 就像这里描述的那样 https github com soumith ganhacks 17 use dropouts in g in both train and test p
  • Office.context.mailbox.displayNewMessageForm 在移动设备中不起作用

    我试图通过单击 Outlook Web 插件中的按钮来创建新的邮件表单 然后使用显示新消息表格 https learn microsoft com en gb office dev add ins reference objectmodel
  • 视图何时附加和分离?

    这个问题是not关于如何检测视图是否已附加或分离 一般来说 什么时候附加或分离视图 有这方面的生命周期图吗 为了澄清 我正在寻找以下情况下发生的情况的答案 活动发送到背景 不透明视图放置在顶部 可见性设置为GONE 视图膨胀 父级分离等 这
  • Yii - 对上传表单进行模型单元测试

    我有以下上传表单模型 class TestUploadForm extends CFormModel public test public function rules return array array test file types
  • JAVACARD2.2中selectApplet()方法的功能是什么

    正如 JavaCard 2 2 API 文档中提到的here http www win tue nl pinpasjc docs apis jc222 javacard framework Applet html selectingAppl
  • 添加包含其他依赖项的模块依赖项

    我正在使用 IntelliJ 12 我有一个Module A其模块依赖于 github 项目 我添加到我的主要Module B依赖于Module A Module A依赖于取决于module1 module2 module3 Module
  • 如何防止滚动视图在数据加载后滚动到网页视图?

    所以我有一个有趣的问题 尽管我没有手动或以编程方式滚动视图 但我的 WebView 会在加载其中的数据后自动滚动 我在 viewpager 中有一个片段 当我第一次加载寻呼机时 它按预期工作并且显示所有内容 但是 一旦我 翻转页面 数据就会