Android WebView 不可滚动

Aba*_*cus 3 java android scroll webview

我的安卓WebView不能滚动。

XML 代码:

<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" />
Run Code Online (Sandbox Code Playgroud)

我正在使用正常webview.loadUrl(url);功能加载网站,有时使用该webview.loadDataWithBaseURL("", htmlContent, "text/html", "UTF-8", "");功能加载网站,它们都显示页面,但它们不可滚动

在里面:

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

加载:

            webview.loadUrl(url);
            [either one of them or the other]
    webview.loadDataWithBaseURL("", htmlContent, "text/html", "UTF-8", "");
Run Code Online (Sandbox Code Playgroud)

Sre*_* GS 5

我已经找到了解决方案,您只需要将 WebView 定义放在“

布局/content_my.xml

" 不在 "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" />
Run Code Online (Sandbox Code Playgroud)

在 MyActivity.java 里面

    WebView webview = (WebView)findViewById(R.id.webView);
    webview.loadUrl("file:///android_asset/index.html");
    webview.setVerticalScrollBarEnabled(true);
    webview.setHorizontalScrollBarEnabled(true);
Run Code Online (Sandbox Code Playgroud)