【问题标题】:Android Webview is scrolling to the top when click on link单击链接时,Android Webview 滚动到顶部
【发布时间】:2017-12-05 00:28:12
【问题描述】:

我有一个 Webview 在我的应用程序中加载静态 html 内容。

问题是,当我点击链接或嵌入内容时(推文、youtube 视频),webview 正在滚动回顶部

看起来像here提到的JS问题

我尝试使用 NestedScrollView 或一些带有参数的技巧,例如

android:focusableInTouchMode="true"

在 LinearLayout 父级中,但没有任何作用

这是我的 xml:

  <android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <WebView
      android:id="@+id/article_webview"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"/>
  </android.support.v4.widget.NestedScrollView>

它将在回收站视图中。

我的问题是:

有没有办法在 webview 设置或 xml 中防止这种行为?

谢谢!

【问题讨论】:

  • 嗨,保罗,您找到解决方案了吗?
  • 嗨,保罗,您找到解决方案了吗?

标签: android webview scroll android-recyclerview


【解决方案1】:

我也遇到了同样的问题。我的WebView 也在RecyclerView 中。

当我在我的RecyclerView 上添加android:descendantFocusability="blocksDescendants" 时,问题不再发生在我身上。

<androidx.recyclerview.widget.RecyclerView
  android:descendantFocusability="blocksDescendants"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"/>

【讨论】:

  • WebView 在使用这个时不允许焦点。输入字段不可编辑。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-06-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-07
  • 1970-01-01
相关资源
最近更新 更多