【发布时间】: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