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>
Ali
  • 3,346
  • 4
  • 21
  • 56

3 Answers3

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"
  • can u explain how does `layout_alignParentTop`, `layout_alignParentLeft`, `layout_alignParentStart` will work inside **`LinearLayout`** – AskNilesh Nov 29 '18 at 04:26
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

  • [`fill_parent` is deprecated](https://developer.android.com/reference/android/view/ViewGroup.LayoutParams#FILL_PARENT) – AskNilesh Nov 29 '18 at 04:24
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"/>
Uma Achanta
  • 3,669
  • 4
  • 22
  • 49