2

I need to make text view with image at right. I need make text wrap around the image at left.

Text may be different length. Image place at top-right always.

Image example:

enter image description here

Х - measns image place.

Nik
  • 7,114
  • 8
  • 51
  • 75
  • Try this http://stackoverflow.com/questions/8953379/android-add-image-to-text-in-text-view – NaviRamyle Feb 08 '13 at 07:34
  • I can place image at left of text using ImageSpan, but I dont know how to place image at right and make text wrap around image. – Nik Feb 08 '13 at 07:36

1 Answers1

0

The basic and simple way to achieve this...!

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

Arpit Garg
  • 8,476
  • 6
  • 34
  • 59