2013-04-23 67 views
0

的android TextView中显示这是我的XML字符串的内容:图像是使用html.fromHtml

<style> 
    img {padding:0 10px 10px 0; width:99% !important;} 
    p,div,ul,ol,em,a,span,u,strong,strike,h1,h2,h3,h4,h5,h6 
    {font-family: verdana;font-size: 14px;color: #fff;} 
    html,body{background:#414042;} 
    a{ color:#3400f3;}p{width:100%;} 
</style> 

<p> 
    <img alt="Ajay Devgn" pimcore_disable_thumbnail="true" pimcore_id="6813" 
    pimcore_type="asset" src="http://dev2.mercuryminds.com/bolly/feb2013/ 
    bolly---ajay-devgn-on-a-satyagraha/kangna-and-kareena.jpg" style="width: 500px; 
    height: 370px; float: left;" /> 
</p> 

这里的图像是在Android TextView的显示。

但图像不显示....我的代码有什么错?我怎样才能显示在TextView的图像......请给我的解决方案...

String fullcontent = in.getStringExtra("Content"); 
     content = fullcontent.substring(1);  
     content = (TextView) findViewById(R.id.title1); 
     content.setText(Html.fromHtml(full_content)); 
+2

什么让你决定使用TextView,因为你要显示图像?看起来你真正需要的是一个WebView。 – RRTW 2013-04-23 06:58:50

+1

这将帮助你http://stackoverflow.com/questions/2865452/is-it-possible-to-display-inline-images-from-html-in-an-android-textview – Pragnani 2013-04-23 07:01:59

回答

3
public static Spanned fromHtml (String source) 

在API级别1 返回显示风格从所提供的HTML字符串文本。 HTML中的任何标签都将显示为一个通用的替换图像,然后您的程序可以通过并替换真实图像。

这使用TagSoup来处理真正的HTML,包括在野外发现的所有破碎。

所以insted的是使用

public static Spanned fromHtml (String source, Html.ImageGetter imageGetter, Html.TagHandler tagHandler) 

返回从提供的HTML字符串显示的样式文本。 HTML中的任何标记都将使用指定的ImageGetter来请求图像的表示(如果不需要,则使用null),并使用指定的TagHandler处理未知标记(如果不需要,则指定null)。

这使用TagSoup来处理真正的HTML,包括在野外发现的所有破碎。

欲了解更多详情,请点击此处answer;