Android WebView不可滚动 [英] Android WebView isn't scrollable

查看:56
本文介绍了Android WebView不可滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Android WebView 无法滚动.

My Android WebView isn't scrollable.

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" />

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

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

初始化:

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

正在加载:

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

推荐答案

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

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

layout/content_my.xml

layout/content_my.xml

"不在"activity_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" />

在MyActivity.java内部

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);

这篇关于Android WebView不可滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆