【问题标题】:webview inside NestedScrollView cause height issueNestedScrollView 中的 webview 导致高度问题
【发布时间】:2015-12-07 07:56:46
【问题描述】:

我使用 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>

使用这种布局,webview 需要滚动很多(抱歉链接,我不能发布图片)

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

【问题讨论】:

    标签: android webview android-coordinatorlayout coordinator-layout nestedscrollview


    【解决方案1】:

    我们正在做同样的事情。谷歌的开发人员和设计人员已经对此进行了分类。目前提供的解决方案是不在 NestedScrollView 中使用 Android webviews。

    这里是线程here的摘录:

    这是WAI。

    如果你把webview放在一个NestedScrollView中,height就是wrap_contents,并且 webview 扩展为页面大小。这就像在桌面上一样, 您将浏览器窗口的大小调整为页面的高度,使其无法滚动 垂直。滚动发生在 NestedScrollView 而不是 webview 本身。

    所以页面中没有js的结果是看到任何滚动事件,所以它 不知道你已经滚动到页面末尾加载更多内容。

    硬件层也由 GL 纹理支持,它们有一个最大值 尺寸(这是最小的屏幕尺寸,虽然通常不多 大)。如果视图变得大于最大纹理大小,则 它不适用于硬件层。这适用于任何视图,而不是 只是网页视图。

    解决方案:不要将 webview 放在 NestedScrollView 中。不要使用网络视图 在 wrap_contents 模式下。让 webview 滚动网页本身。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-30
      • 2016-02-14
      • 2013-03-13
      • 2016-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多