使用 Html.fromHtml() 查看 HTML 代码不会获取图像 - Android



我正在开发一个新闻应用程序。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>";

如你所见,在"result"里面有2个图片url。"result"为整篇文章的内容。

当我使用TextView查看这篇文章的内容时,图像不显示:

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

如何显示这篇文章的内容适合屏幕和所有图像显示。这是我的代码。

谢谢你的帮助

你需要一个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>

最新更新