Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android WebView isn't scrollable

My Android WebView isn't scrollable.

XML Code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/screen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#87cefa"
android:gravity="left"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<WebView
    android:id="@+id/webView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_centerHorizontal="true" />

I'm loading the Website with the normal webview.loadUrl(url); function and sometimes with the webview.loadDataWithBaseURL("", htmlContent, "text/html", "UTF-8", ""); function, both of them display the page, but they are not scrollable

Init:

setContentView(R.layout.activity_main); webview = (WebView)this.findViewById(R.id.webView); webview.setVerticalScrollBarEnabled(true); webview.setHorizontalScrollBarEnabled(true);

Loading:

            webview.loadUrl(url);
            [either one of them or the other]
    webview.loadDataWithBaseURL("", htmlContent, "text/html", "UTF-8", "");
like image 746
Abascus Avatar asked Sep 13 '25 21:09

Abascus


1 Answers

I have found a solution for this, All you need is to put WebView definition in "

layout/content_my.xml

" not in "activity_my.xml"

<WebView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/webView"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

And inside the MyActivity.java

    WebView webview = (WebView)findViewById(R.id.webView);
    webview.loadUrl("file:///android_asset/index.html");
    webview.setVerticalScrollBarEnabled(true);
    webview.setHorizontalScrollBarEnabled(true);
like image 74
Sreedhar GS Avatar answered Sep 15 '25 10:09

Sreedhar GS