Text wrapping around image

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


Sponsored Links
 Hi,

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

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.

Thanks.
--~--~---------~--~----~------------~-------~--~----~



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)
{
line.draw(width);
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
Spannable.

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



Other Threads

1. debug messages on stdout

hi all ,

we are trying to play a mp4 file using OMX hardware plugins ,due to
some problem the video is not playing .

we would like to see the DMAI and CE debug messages to get to know
where exactly is the problem.

tried exporting the variables DMAI_DEBUG = 2 and CE_DEBUG = 3 ,but we
are unable to see any debug messages .in android by default the stdout
and stderr messages are sent to /dev/null ,we think this may be the
problem for not seeing CE and DMAI debug messages.

can anyone help us how to redirect DMAI and CE debug messages onto the
logcat ?any help is appreciated.

thanks ,
siva.

-- 

2. Hello Views GridView Tutorial - Android Packaging Problem

I've got a similar error:

Description
Resource            Path        Location             Type
Unparsed aapt error(s)! Check the console for output.
HelloGridView                   Unknown     Android Packaging Problem

There is no clue about the error, just this line im "Problems" menu of
Eclipse...

Can someone give any directions?

Thanks in advance.

-- 

3. proxy tool

4. Run binary application from android source code and get stdout - problem permission denied

5. Android Widget Binder Transaction

6. Urgent Need : Sr. Java Developer(9 Opening) in Columbus, OH for 6 month contract

7. How to call the dialog of a DialogPreference withouth requiring the user to click on it?