使用Html.fromHtml()查看HTML代码并不能获得图像 - Android

时间:2013-05-23 11:09:18

标签: android html web-services textview

我正在开发一个新闻应用程序。 Webservice返回一个HTML代码字符串。这是文章的内容:

String result;
// result is returned from Webservice
result = "<p>Simply put, the 2013 Billboard Music Awards included a sizable helping of Bieber, with two performances in three hours and a Top Male Artist win before the Milestone Award was presented. Three months after another Justin -- Mr. Timberlake -- kept popping up at the 2013 Grammys and threatened overexposure, perhaps the audience at the Billboard Music Awards simply tired of seeing Bieber show up on stage and snag more of the spotlight.<br/><img align=\"Middle\" alt=\"\" border=\"0\" class=\"oImage\" height=\"335\" src=\"http://img2.news.zing.vn/2013/05/22/u2.jpg\" width=\"500\" \\/><br/>Plus, in the middle of the perceived mayhem was a monster-selling tour, with tons of Beliebers blissfully taking in the spectacle. But a dark cloud seemed embedded within the scraps of news coming from Bieber's tour over the past few months, and the Billboard Music Award boos could have been festering ill will toward one, some or all of them.<br/><img align=\"Middle\" alt=\"\" border=\"0\" class=\"oImage\" height=\"289\" src=\"http://img2.news.zing.vn/2013/05/22/u1.jpg\" width=\"500\"/></p>";

如您所见,“结果”中有2个图片网址。 “结果”是整篇文章的内容。

当我使用TextView查看本文的内容时,图像不会显示:

TextView content = (TextView) findViewById(R.id.tvContent);
content.setText(Html.fromHtml(result));

如何显示符合屏幕的本文内容,并显示所有图像。 这是my code

感谢帮助。

1 个答案:

答案 0 :(得分:0)

你需要一个Webview。没有textview。以下是它的实施方式。

    Description = (WebView)findViewById(R.id.webView1);
        Description.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
        WebSettings webSettings = Description.getSettings();
        webSettings.setTextSize(WebSettings.TextSize.NORMAL);
Description.loadDataWithBaseURL (null, "<html><p>Simply put, the 2013 Billboard Music Awards included a sizable helping of Bieber, with two performances in three hours and a Top Male Artist win before the Milestone Award was presented. Three months after another Justin -- Mr. Timberlake -- kept popping up at the 2013 Grammys and threatened overexposure, perhaps the audience at the Billboard Music Awards simply tired of seeing Bieber show up on stage and snag more of the spotlight.<br/><img align=\"Middle\" alt=\"\" border=\"0\" class=\"oImage\" height=\"335\" src=\"http://img2.news.zing.vn/2013/05/22/u2.jpg\" width=\"500\" \\/><br/>Plus, in the middle of the perceived mayhem was a monster-selling tour, with tons of Beliebers blissfully taking in the spectacle. But a dark cloud seemed embedded within the scraps of news coming from Bieber's tour over the past few months, and the Billboard Music Award boos could have been festering ill will toward one, some or all of them.<br/><img align=\"Middle\" alt=\"\" border=\"0\" class=\"oImage\" height=\"289\" src=\"http://img2.news.zing.vn/2013/05/22/u1.jpg\" width=\"500\"/></p></html>", "text/html", "UTF-8",null);

你的布局,

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
            <WebView
                android:id="@+id/webView1"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />

   </RelativeLayout>