1

私は次のようなHTML文字列を持っています

String htmlstr=" This is my image <img src='/sdcard/pic1.jpg' /> and the my second image is <img src='/sdcard/pic2.jpg' />"

使ってます

txtimg.setText(Html.fromHtml(htmlstr));

しかし、問題は、画像の代わりに緑色のデフォルトの小さな正方形を1つ表示することです

画像の表示を手伝ってください

前もって感謝します

4

2 に答える 2

5

これを試して :

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);

それは私にとってうまくいきます。

ありがとう。

于 2013-01-17T13:07:35.867 に答える
3

それは私のために次のように働いた

txtimg.setText(Html.fromHtml(htmlstr, new ImageGetter() {                 
                @Override
                public Drawable getDrawable(String source) {
                    String path =  source;

                    Drawable bmp = Drawable.createFromPath(path);
                    bmp.setBounds(0, 0, bmp.getIntrinsicWidth(), bmp.getIntrinsicHeight());

                    return bmp;
                }
            }, null));
于 2013-01-17T13:32:37.160 に答える