Android TextView显示html图片

Java代码  收藏代码
  1. html = "<h1>this is h1</h1>"  
  2.                 + "This text is normal  
  3. "  
  4.                 + "<img src='http://www.nzdb.com.cn/Portals/0/picture/zhy/%E6%B0%AE%E8%82%A51.jpg' />";  
  5. charSequence = Html.fromHtml(html, imgGetter, null);  
  6. infoContent.setText(charSequence);  



Java代码  收藏代码
    1. ImageGetter imgGetter = new Html.ImageGetter() {    
    2.         public Drawable getDrawable(String source) {    
    3.             Log.i("RG", "source---?>>>" + source);    
    4.             Drawable drawable = null;    
    5.             URL url;    
    6.             try {    
    7.                 url = new URL(source);    
    8.                 Log.i("RG", "url---?>>>" + url);    
    9.                 drawable = Drawable.createFromStream(url.openStream(), ""); // 获取网路图片    
    10.             } catch (Exception e) {    
    11.                 e.printStackTrace();    
    12.                 return null;    
    13.             }    
    14.             drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),    
    15.                     drawable.getIntrinsicHeight());    
    16.             Log.i("RG", "url---?>>>" + url);    
    17.             return drawable;    
    18.         }    
    19.     };  
posted @ 2014-11-18 09:13  七八九一  阅读(752)  评论(0编辑  收藏  举报