【问题标题】:Webview Content scrolling enable inside main scrollview在主滚动视图内启用 Webview 内容滚动
【发布时间】:2020-01-08 12:39:42
【问题描述】:

我正在创建一个应用程序,其中我需要将 webview 放入滚动视图中。我正在使用 NestedScrollview。另外,我想在 webview 中滚动内容。

我的 webview 加载一个 HTML,其中包含地图 + 一些数据列表。因此,当我从 web 滚动列表时它不起作用并且外部 Scrollview 的滚动被滚动。我想要一个地图和列表都可以在 webview 中滚动。

 <android.support.v4.widget.NestedScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fillViewport="true">
       <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp"
        android:layout_marginRight="10dp"
        android:fontFamily="@font/avenirnextltpro_regular"
        android:text="df"
        android:textColor="@color/black"
        android:textSize="@dimen/title_textsizeBig"
     />
   ......... other views like image, Button etc........
      <WebView
       android:id="@+id/webviewWalkscore"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:layout_marginStart="8dp"
       android:layout_marginLeft="8dp"
       android:layout_marginTop="8dp"
       android:layout_marginEnd="8dp"
       android:layout_marginRight="8dp"
     />

    </android.support.v4.widget.NestedScrollView>

在 Java 文件中,我为 webview 添加了此设置

    webview.getSettings().setJavaScriptEnabled(true);
    webview.getSettings().setGeolocationEnabled(true);
    webview.setVerticalScrollBarEnabled(true);
    webview.getSettings().setLoadWithOverviewMode(true);
    webview.getSettings().setUseWideViewPort(true);
    webview.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
    webview.setScrollContainer(true);
    webview.loadUrl("<url with map and list>")

【问题讨论】:

  • WebView 本身支持滚动。如果删除 NestedScrollView 会发生什么?
  • 如果删除 NestedScrollView 仍然无法正常工作。我尝试了 Scrollview 和 NestedScrollView 。我有更多视图,所以需要滚动视图。

标签: android webview scroll scrollview nestedscrollview


【解决方案1】:

尝试使用实现 NestedScrollingParent2 的自定义 ViewGroup 布局并将其放入 webview 和其他视图中。并让 webview 实现 NestedScrollingChild。在您的 webview 中覆盖 onTouch 或 intercepttouch。在您的父布局中覆盖 dispatchTouch 事件。将触摸事件传递给 webview,然后它将在 ACTION MOVE 中用于调用 dispatchStartNestedScroll。 访问此链接。尝试从中获得想法。 https://github.com/HzwSunshine/NestedWebViewRecyclerViewGroup/blob/master/NestedWebViewRecyclerViewGroup/src/main/java/com/hzw/nested/NestedScrollWebView.java

https://github.com/HzwSunshine/NestedWebViewRecyclerViewGroup/blob/master/NestedWebViewRecyclerViewGroup/src/main/java/com/hzw/nested/NestedWebViewRecyclerViewGroup.java

https://www.programmersought.com/article/62784442040/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-09
    • 2012-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-07
    相关资源
    最近更新 更多