Hem*_*h07 1 android image textview
我有如下HTML字符串
String htmlstr=" This is my image <img src='/sdcard/pic1.jpg' /> and the my second image is <img src='/sdcard/pic2.jpg' />"
Run Code Online (Sandbox Code Playgroud)
我在用
txtimg.setText(Html.fromHtml(htmlstr));
Run Code Online (Sandbox Code Playgroud)
但问题是它显示1个默认小方块,绿色而不是图像
请帮我显示图像
提前致谢
试试这个 :
final String path = Environment.getExternalStorageDirectory().getAbsolutePath()+"/test.jpg";
ImageGetter imageGetter = new ImageGetter() {
public Drawable getDrawable(String source) {
Drawable d = Drawable.createFromPath(path);
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
return d;
}
};
Spanned htmlstr= Html.fromHtml("<img src='" + path + "'/>", imageGetter, null);
TextView out_unit1 = (TextView) findViewById(R.id.mTxtViewCm2);
out_unit1.setText(htmlstr);
Run Code Online (Sandbox Code Playgroud)
这对我来说很有用.
谢谢.