Android TextView右侧有图片

时间:2013-02-08 07:32:38

标签: android textview imageview textwrapping

我需要在右边用图像进行文本查看。我需要在左边的图像周围进行文本环绕。

文字的长度可能不同。图像位置始终位于右上角。

图片示例:

enter image description here

Х - measns image place。

1 个答案:

答案 0 :(得分:0)

实现这一目标的基本而简单的方法......!

final String testContent = "<html><body><img src=\"ic_launcher.png\" style=\"float:right;\"/>This is like testing if this thing works   ghdjdhfjkhgdjkhgkfdjgkljdfkljgklfdjkgljkfd kljlk lj kld jgkljdklgjfdkljgkfldjg kljfdkl dklfgjklfdj gklfdjklg This is like testing if this thing works ghdjdhfjkhgdjkhgkfdjgkljdfkljgklfdjkgljkfd kljlk lj kld jgkljdklgjfdkljgkfldjg kljfdkl dklfgjklfdj gklfdjklg jdfklgjkdfljg kldfjgkljdfklgjdklf. It XXX"
                + " in a more elaborate This is like testing if this thing works ghdjdhfjkhgdjkhgkfdjgkljdfkljgklfdjkgljkfd kljlk lj kld jgkljdklgjfdkljgkfldjg kljfdkl dklfgjklfdj gklfdjklg jdfklgjkdfljg kldfjgkljdfklgjdklf. It XXX"
                + " in a more elaborate This is like testing if this thing works ghdjdhfjkhgdjkhgkfdjgkljdfkljgklfdjkgljkfd kljlk lj kld jgkljdklgjfdkljgkfldjg kljfdkl dklfgjklfdj gklfdjklg jdfklgjkdfljg kldfjgkljdfklgjdklf. It XXX"
                + " in a more elaborate jdfklgjkdfljg kldfjgkljdfklgjdklf. It XXX";

        textView.setText(Html.fromHtml(testContent, imgGetter, null));

    }

    private ImageGetter imgGetter = new ImageGetter() {

        public Drawable getDrawable(String source) {
            Drawable drawable = null;
            if (imageNumber == 1) {
                drawable = getResources().getDrawable(R.drawable.ic_launcher);
                ++imageNumber;
            } else
                drawable = getResources().getDrawable(R.drawable.ic_launcher);
            drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
                    drawable.getIntrinsicHeight());

            return drawable;
        }
    };

Screen Shot 1 Screen Shot 2