【问题标题】:Html in textview: problems with frame layout scrolling and image viewingtextview 中的 Html:框架布局滚动和图像查看问题
【发布时间】:2012-08-31 00:55:13
【问题描述】:
<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:

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

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

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

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

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

【问题讨论】:

标签: android textview


【解决方案1】:

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

【讨论】:

  • 有效!还有一个小问题:我想手动设置背景和文本颜色,以使 html 适应我的应用程序 ui.. 可以吗?
  • 另一个问题是关于编码:在我的 html 中,我经常使用 "è","à","ì",... 而且,虽然将编码设置为 "iso 8859-1",但它仍然可以不显示它们
  • 你能发布你的代码吗?更新您的问题并添加用于在 WebView 中加载 HTML 的代码。
【解决方案2】:

您可以将 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 >

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多