亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android中TextView顯示插入的圖片實(shí)現(xiàn)方法

 更新時(shí)間:2016年08月11日 10:54:46   作者:與時(shí)俱進(jìn)  
這篇文章主要介紹了Android中TextView顯示插入的圖片實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了TextView三種顯示插入圖片的實(shí)現(xiàn)技巧,需要的朋友可以參考下

本文實(shí)例講述了Android中TextView顯示插入的圖片實(shí)現(xiàn)方法。分享給大家供大家參考,具體如下:

Android系統(tǒng)默認(rèn)給TextView插入圖片提供了三種方式:

1、ImageSpan
2、Html.ImageGetter
3、TextView.setCompoundDrawables(left, top, right, bottom)

1、TextView使用ImageSpan顯示圖片

ImageSpan span = new ImageSpan(this, R.drawable.ic_launcher);
SpannableString spanStr = new SpannableString("http://chabaoo.cn");
spanStr.setSpan(span, spanStr.length()-1, spanStr.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
mTVText.setText(spanStr);

PS:關(guān)于SpannableString相關(guān)的其他span,查看:[Android教程]TextView使用SpannableString設(shè)置復(fù)合文本

2、使用Html.ImageGetter顯示網(wǎng)頁中的圖片

查看文章:[Android教程]TextView顯示Html類解析的網(wǎng)頁和圖片及自定義標(biāo)簽

3、在TextView四周顯示圖片

mTVText.setText("setCompoundDrawables");
Drawable d = getResources().getDrawable(R.drawable.ic_launcher);
d.setBounds(0, 0, 50, 50); //必須設(shè)置圖片大小,否則不顯示
mTVText.setCompoundDrawables(d , null, null, null);

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開發(fā)入門與進(jìn)階教程》、《Android多媒體操作技巧匯總(音頻,視頻,錄音等)》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論