TextView顯示插入的圖片


Android系統默認給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://orgcent.com");
spanStr.setSpan(span, spanStr.length()-1, spanStr.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
mTVText.setText(spanStr);
PS:關於SpannableString相關的其他span,查看[Android教程]TextView使用SpannableString設置復合文本
2、使用Html.ImageGetter顯示網頁中的圖片
查看文章:[Android教程]TextView顯示Html類解析的網頁和圖片及自定義標簽
3、在TextView四周顯示圖片
mTVText.setText("setCompoundDrawables");
Drawable d = getResources().getDrawable(R.drawable.ic_launcher);
d.setBounds(0, 0, 50, 50); //必須設置圖片大小,否則不顯示
mTVText.setCompoundDrawables(d , null, null, null);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM