Text wrapping around image

by focuser » Sun, 18 Oct 2009 01:16:33 GMT

Sponsored Links

I know this has been brought up before, but I couldn't find a solution

I'd like to get the similar layout on an Activity as this html
fragment in a browser, basically making text wrapping around an image:

<img src="rainbow.gif" align="left">
bla bla bla bla bla
bla bla bla bla bla
bla bla bla bla bla

I tried the following but no luck yet:
 - None of the current layouts supports this.
 - a TextView and using Html.fromHTML, but that doesn't seem to
understand the "align" attribute -- No matter what "align" equals to,
it just places the image in the same line of the first line of text,
and never aligns multiple lines of text along side the image.  Styles
don't work either.
 - I looked up the doc of ImageSpan, but its verticalAlignment only
supports "bottom" and "baseline".  Should I use "baseline"?  I tried
it but seems no effect, maybe I'm missing something?
 - A hack: using two TextView, one to the right of the image, and
another below the image, and set the maxLines of the first TextView to
be approximately the height of the image.  But the problem is I
couldn't get the *last visible character* for the text.

 I don't want to use WebView since it seems to be too much overhead
for such a simple view.


Text wrapping around image

by focuser » Tue, 20 Oct 2009 23:41:19 GMT

 anyone could help?


Sponsored Links

Text wrapping around image

by Matt Kanninen » Wed, 21 Oct 2009 02:02:27 GMT

 I spent a fair amount of time doing the same thing.  Html.fromHTML is
helpful, but it seems to basically take each <img> tag it encounters
and add it to the textview like a character.  So you can have one line
of text to the left, and one line to the right, but you cant have
multiple lines of text on each side.

I used a similar hack.  I called measureText on the Paint attached to
the TextView, to estimate how much of a given CharSequence would fit
in a first textView adjacent to an image.  I then took the remaining
portion of the CharSequence and gave it to a TextView under the image.

 http://developer.android.com/reference/android/graphics/Paint.html #measureText%28java.lang.CharSequence,%20int,%20int%29

This was ugly though because I needed the width of the ImageView and
it's container to be determined already.  It took more logic then I
had time for to try to get it to calculate it all properly.  I tried
browsing into the source for TextView

 http://android.git.kernel.org/?p=platform/frameworks/base.git ;a=blob_plain;f=core/java/android/widget/TextView.java

but didn't come away with too much of use.

Has anyone wrapped multiple lines of text around an image that is
multiple lines tall?


Text wrapping around image

by devileper » Sat, 24 Oct 2009 06:38:45 GMT

 nly the first line can wrap around the image due to a limitation in
the StaticLayout class. The logic is very rudimentary and performs a
special indent for the first line but ignores this for all other
lines. The logic is as follows:

width = firstWidth;
for (line in text)
width = restWidth;

Therefore it appears impossible to accomplish what you are
describing. My only suggestion would be to override the
TextView.makeNewLayout and use your own layout class to format the

On Oct 20, 11:01am, Matt Kanninen <mathias...@gmail.com> wrote:

Other Threads

1. Google gadget on Andorid

Hi ..All

I have some quesitons about Android.

First one is:
I have been implement a google desktop gadget, but now


2. Google App Developers Class Action Lawsuit

If any developer is looking to join this class action lawsuit against
google, please email us at: heavysportsw...@yahoo.com

A class action lawsuit is its early stages against Google for its
unfair practices against app developers. Google terminates android
developer accounts without notice or good merit, making developers pay
for registration and removing their accounts with no merit. Google has
no source of communication besides automated email replies. Becker &
Associates has taken this class action lawsuit seriously and will be
filing in the California Courts within this month.


3. av_seek_frame problem

4. Bitmap.createScaledBitmap Error

5. Unsatisfied Link Error

6. Unable to execute shell command using Runtime.getRuntime().execute("logcat -d");

7. How to distinguish url redirection and normal link click in webview?