嵌套在NestedScrollView中的WebView导致高度问题

5
我是一名有用的助手,可以为您翻译文本。

我使用support.v4.widget.NestedScrollView,并且我的webview出现了问题。

这是我的布局:

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:id="@+id/barlayout">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:background="#9E9E9E"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_scrollFlags="scroll|enterAlways">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/relativeLayout"
            android:animateLayoutChanges="true">

            <!-- some views here -->

        </RelativeLayout>

    </android.support.v7.widget.Toolbar>

</android.support.design.widget.AppBarLayout>

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <WebView
        android:id="@+id/webView"
        android:layout_height="match_parent"
        android:layout_width="match_parent" />

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

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ProgressBar
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/progressBar"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"/>

    <include
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        layout="@layout/dialog_location"
        android:id="@+id/dialog"
        android:visibility="invisible"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

</RelativeLayout>

使用这种布局,网页视图会有太多的滚动(抱歉无法发布图片链接)。

https://drive.google.com/open?id=0B7otV-_1sdEvUWRzSjlHY01fY3c

如果我将Webview更改为wrap_content,那么Webview会很小。
<WebView
        android:id="@+id/webView"
        android:layout_height="wrap_content"
        android:layout_width="match_parent" />

https://drive.google.com/open?id=0B7otV-_1sdEvbVFSRlR0a2IxeUk

1个回答

2
我们正在做同样的事情。这已经被分配给了谷歌的开发者和设计师。目前提供的解决方案是不要在NestedScrollView内使用Android webview。
以下是来自此处的摘录:
这是WAI。 如果将webview放入NestedScrollView中,高度为wrap_contents,则webview会扩展到页面的大小。这就像在桌面上,您调整浏览器窗口的高度以使其无法垂直滚动一样。滚动发生在NestedScrollView而不是webview本身中。 因此,页面中没有js看到任何滚动事件,因此它不知道您是否滚动到页面末尾加载更多内容。 此外,硬件层由GL纹理支持,并且它们具有最大尺寸(至少是屏幕尺寸,尽管通常不会更大)。如果视图变得大于最大纹理大小,则它将无法与硬件层一起使用。这适用于任何视图,而不仅仅是webview。 解决方案:不要将webview放入NestedScrollView中。不要在wrap_contents模式下使用webview。让webview自己滚动网页。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接