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. Rings Extended obsoleted by new builds?

Hi all (hoping Ms Hackborn might see this post as well)

I know this might seem off-topic but it does have to do with
development of an application.  There is a lot of info here so I
apologize for the long-winded post... here goes.

My application utilizes a ringtone picker and what I'm finding is that
in some cases *it seems like* the default ringtone that a user sets
for their phone is not *truly* the default ringtone systemwide.

My application also does not set the ringtone for the phone - it
merely uses it in its own scope, that is, it does not affect any
systemwide settings.

Now one of the users of this app has reported to me that he has Rings
Extended installed and that's how he sets his default ringtone for his
phone.  What my app does is:

1.  user uses default ringtone in ringtone picker in application scope
2.  user hits ok
3.  ringtone's actual URI is resolved from content://settings/system/ringtone
and stored for later use

What it seems like is happening is that the default ringtone URI is
still pointing to the original default ringtone - i.e. the one that is
the factory-defined default.   So when they play the default ringtone
in my app, they get that factory-defined one... not the one they have
defined as the default ringtone.

On the other hand, I don't have Rings Extended installed anymore
because it seems that the functionality that it achieved is now
performed by the build - I'm using RC33.  My default ringtone is set
systemwide and the URI is content://settings/system/ringtone.  To get
the system to see ringtones on my SD card, I simply mount it, copy the
ringtones to Ringtones, unmount, and then they show up in ringtone

I don't know what build this user is using at the moment.

Sorry if this is a lot to digest but is Rings Extended obsolete now?
I don't want to tell users of my app to uninstall it if it's working
for them... that wouldn't seem nice.  Perhaps T-Mobile has not pushed
out newer/newest builds to everyone?  I'm confused - it's hard to tell
who has what, it seems.


2. Should i use master or cupcake branches?

Hi, everybody:
If I want develope some products base on android, which source branch should i 
use? The master or the cupcake branch? What's the difference between them, and 
which one is more stable?
thanks a lot!




unsubscribe: android-porting+unsubscr...@googlegroups.com

3. a such strange problem when packaging some files under assets folder

4. Announcing OpenCORE 2.1 release

5. Distinguishing Between Edge and 3G network

6. For Bluetooth File Transfer What I can do?

7. How to access "shared data/settings" across multiple application? ContentProvider or SharedPreferences?