Android WebView在滚动结束时不加载新内容。

huangapple go评论60阅读模式
英文:

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

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;androidx.swiperefreshlayout.widget.SwipeRefreshLayout
    xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    android:id=&quot;@+id/web_view_refresh&quot;
    android:layout_width=&quot;match_parent&quot;
    android:layout_height=&quot;match_parent&quot;&gt;
    &lt;FrameLayout
        android:layout_width=&quot;match_parent&quot;
        android:layout_height=&quot;match_parent&quot;&gt;
        &lt;com.facebook.shimmer.ShimmerFrameLayout
            android:id=&quot;@+id/web_view_loading&quot;
            android:layout_width=&quot;match_parent&quot;
            android:layout_height=&quot;match_parent&quot;
            android:visibility=&quot;gone&quot;&gt;
            &lt;LinearLayout
                android:layout_width=&quot;match_parent&quot;
                android:layout_height=&quot;match_parent&quot;
                android:orientation=&quot;vertical&quot;&gt;

               ***** OTHER COMPONENTS ******

            &lt;/LinearLayout&gt;
        &lt;/com.facebook.shimmer.ShimmerFrameLayout&gt;
        &lt;androidx.core.widget.NestedScrollView
            android:id=&quot;@+id/scroll_web_view&quot;
            android:layout_width=&quot;match_parent&quot;
            android:layout_height=&quot;match_parent&quot;&gt;
            &lt;WebView
                android:id=&quot;@+id/web_view&quot;
                android:layout_width=&quot;match_parent&quot;
                android:layout_height=&quot;wrap_content&quot;/&gt;
        &lt;/androidx.core.widget.NestedScrollView&gt;
    &lt;/FrameLayout&gt;
&lt;/androidx.swiperefreshlayout.widget.SwipeRefreshLayout&gt;

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);

huangapple
  • 本文由 发表于 2023年6月8日 16:44:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/76430094.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定