Android WebView - scrollbar don't fill the layout_height
Asked Answered
I

3

7

I have a WebView with large text content. I'm using the following WebView settings:

    settings.setJavaScriptEnabled(true);
    settings.setLoadWithOverviewMode(true);
    settings.setUseWideViewPort(true);
    settings.setSupportZoom(false);
    settings.setBuiltInZoomControls(false);
    webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    webview.setScrollbarFadingEnabled(false);

The Html viewport settings are:

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />

The problem is that the scrollbar is going outside the layout, as follow:

My Android Layout is:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?android:attr/actionBarSize"
        android:background="@color/colorPrimary"
        android:elevation="4dp"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

    <LinearLayout
        android:id="@+id/frame_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent">


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


    </LinearLayout>
</LinearLayout>
Israelite answered 22/11, 2018 at 12:53 Comment(4)
Are you able to scroll the last line of text or its hiding behind bottom menu buttons ?Fecundate
I can go to the last line of Html content (text) but when I'm there the scrollbar is gone.Israelite
I think removing content=user-scalable=no or setting it to yes from your html viewport settings should do the trick.Deadening
the bounty is about to end give it to the closest answer or it all goes to wasteEscargot
I
1

I fixed the issue by adding the following on the WebView layout:

android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
Israelite answered 28/11, 2018 at 8:40 Comment(1)
can u explain how does layout_alignParentTop, layout_alignParentLeft, layout_alignParentStart will work inside LinearLayoutHypogeum
C
1

try this :-

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

i fix this issue with this code

Circumnavigate answered 28/11, 2018 at 15:32 Comment(1)
fill_parent is deprecatedHypogeum
C
0

You can add padding to parent layout

    <WebView android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/webView"
    android:padding="3dp"/>
Continuant answered 29/11, 2018 at 9:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.