Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

webview inside NestedScrollView cause height issue

I use support.v4.widget.NestedScrollView and i have an issue with my webview.

Here is my layout:

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

with this layout the webview have to much scroll (sorry for the link, i cant post images)

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

and if i change webview to wrap_content the webview is small

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

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

like image 382
Kakaman593 Avatar asked Oct 30 '22 19:10

Kakaman593


1 Answers

We are doing the exact same thing. This has been triaged to the developers and designers at google. The solution provided as of the moment is not to use Android webviews inside NestedScrollView.

Here is an excerpt from the thread here:

This is WAI.

If you put webview in a NestedScrollView, height is wrap_contents, and the webview expands to the size of the page. This is as if in desktop, you resize the browser window to height of the page so it can't scroll vertically. The scrolling is happening in NestedScrollView rather than webview itself.

So a consequence of no js in the page sees any scroll events, so it doesn't know you've scrolled to the end of the page load more content.

Also hardware layers is backed by GL textures, and they have a maximum size (which is least the screen size, although usually not much bigger). If a view becomes larger than the maximum texture size, then it won't work with a hardware layer. This applies to any view, not just webview.

Solution: don't put webview in a NestedScrollView. don't use webview in wrap_contents mode. Let webview scroll the web page itself.

like image 82
Neon Warge Avatar answered Nov 15 '22 05:11

Neon Warge