我必须将WebView放入ScrollView中,但我需要在webview之前将一些视图放入相同的scrollview中。所以它看起来像这样:
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:id="@+id/articleDetailPageContentLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/articleDetailRubricLine"
android:layout_width="fill_parent"
android:layout_height="3dip"
android:background="@color/fashion"/>
<ImageView
android:id="@+id/articleDetailImageView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitStart"
android:src="@drawable/article_detail_image_test"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dip"
android:text="PUBLISH DATE"/>
<WebView
android:id="@+id/articleDetailContentView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/fashion"
android:isScrollContainer="false"/>
</LinearLayout>
我从后端获取了一些HTML信息。它没有包含任何body或head标签,只是一些被<p>
或<h4>
或其他标签包围的数据。此外,其中也包含了<img>
标签。有时候图片会比当前屏幕宽度还要宽。因此,我在HTML开头添加了一些CSS。我这样将数据加载到webview中:
private final static String WEBVIEW_MIME_TYPE = "text/html";
private final static String WEBVIEW_ENCODING = "utf-8";
String viewport = "<head><meta name=\"viewport\" content=\"target-densitydpi=device-dpi\" /></head>";
String css = "<style type=\"text/css\">" +
"img {width: 100%;}" +
"</style>";
articleContent.loadDataWithBaseURL("http://", viewport + css + articleDetail.getContent(), WEBVIEW_MIME_TYPE,
WEBVIEW_ENCODING, "about:blank");
有时当页面加载时,滚动视图会滚动到网页视图开始的位置。我不知道该如何解决。此外,有时在网页视图内容之后会出现巨大的空白区域。我也不知道该怎么办。
有时滚动视图的滚动条在我滚动时开始随机抖动...
我知道将网页视图放入滚动视图中是不正确的,但似乎我别无选择。有人能建议正确的方法将所有视图和所有 HTML 内容放置到网页视图中吗?