1
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>

<TextView
    android:id="@+id/htmlText"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:textColor="#FFCC00" />

</FrameLayout>

如果我这样设置 textview 的文本:

setText(Html.fromHtml(htmlString));

滚动不起作用。此外,如果在 html 中有一个 img 标签,则不会查看图像..为什么?

编辑:

我切换到网络视图:

WebView view = (WebView)findViewById(R.id.newsView);
view.loadData(htmlString,"text/html","UTF-8");

现在我解决了这些问题,但我还有其他问题:

1)如何设置透明背景以便我可以看到我的应用程序?

2)如何设置前景文本颜色,以便再次看到我的应用程序的颜色?

3)如果有一个img标签图像不适合视图,导致水平滚动。相反,文本完美填充。

4

2 回答 2

1

如果要显示 HTML 内容,请使用WebView. TextView仅支持有限的 HTML 标记集 - 主要用于格式化文本。

于 2012-09-06T08:43:02.303 回答
1

您可以将 ScrollView 用于 textView,它会变为可滚动的。然后使用

htmlText.setText(Html.fromHtml(htmlString));

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true" >

        <TextView
            android:id="@+id/htmlText"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />

    </ScrollView>
</RelativeLayout >
于 2014-03-21T16:20:51.990 回答