Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android WebView - scrollbar don't fill the layout_height

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>
like image 948
Apopei Andrei Ionut Avatar asked Nov 22 '18 12:11

Apopei Andrei Ionut


1 Answers

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

android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
like image 80
Apopei Andrei Ionut Avatar answered Sep 19 '22 06:09

Apopei Andrei Ionut