2013-04-23 68 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;