英文:
Android WebView does not load new content on scroll end
问题
以下是您要翻译的内容:
我的应用的一部分在WebView中显示一个网站。
该网站显示20个项目的块。当您滚动到底部时,将显示下一个20个项目。这在任何Web浏览器中都可以正常工作。
但是在我的WebView中,只显示初始块,当我滚动到底部时什么都不会发生。
WebView的设置:
binding?.webView?.settings?.let {
it.javaScriptEnabled = true
it.domStorageEnabled = true
it.javaScriptCanOpenWindowsAutomatically = true
it.setSupportMultipleWindows(false) // 如果为true,则Webview中的target _blank不可点击
}
Fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/web_view_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.facebook.shimmer.ShimmerFrameLayout
android:id="@+id/web_view_loading"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
***** 其他组件 ******
</LinearLayout>
</com.facebook.shimmer.ShimmerFrameLayout>
<androidx.core.widget.NestedScrollView
android:id="@+id/scroll_web_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@+id/web_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</androidx.core.widget.NestedScrollView>
</FrameLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
我尝试从NestedScrollView中移除WebView,结果导致滚动卡顿,但仍然没有在滚动到底部时显示新内容。
英文:
A part of my app is showing a website inside a WebView.
The website shows chunks of 20 items. When you scroll to the end, the next 20 items are shown. This works fine in any web browser.
In my WebView though, only the inital chunk is shown and nothing happens, when I scroll to the end.
The settings of the WebView:
binding?.webView?.settings?.let {
it.javaScriptEnabled = true
it.domStorageEnabled = true
it.javaScriptCanOpenWindowsAutomatically = true
it.setSupportMultipleWindows(false) // if true, hrefs with target _blank are not clickable in webview
}
The Fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/web_view_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.facebook.shimmer.ShimmerFrameLayout
android:id="@+id/web_view_loading"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
***** OTHER COMPONENTS ******
</LinearLayout>
</com.facebook.shimmer.ShimmerFrameLayout>
<androidx.core.widget.NestedScrollView
android:id="@+id/scroll_web_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@+id/web_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</androidx.core.widget.NestedScrollView>
</FrameLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
I tried to remove the webview from the NestedScrollView. Which resulted in laggy scrolling, but still no new content on scroll end
答案1
得分: 0
需要设置两个属性为true
binding?.webView?.setVerticalScrollBarEnabled(true);
binding?.webView?.setHorizontalScrollBarEnabled(true);
英文:
You need to set true
two properties
binding?.webView?.setVerticalScrollBarEnabled(true);
binding?.webView?.setHorizontalScrollBarEnabled(true);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论