Text around image

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Text around image

Postby sanyiii » Thu Feb 11, 2010 11:36 am

Hi everybody!

I want to create a view, which has a long text, and an image on top right corner. But i want to wrap this text around this image. The android:drawableRight attribute is not good for me.
As i know, the layouts don't support this. Which is the best way to do this?
sanyiii
Developer
Developer
 
Posts: 42
Joined: Wed Jun 10, 2009 9:58 am

Top

Postby jonw » Thu Feb 11, 2010 3:44 pm

I haven't seen this done, well apart from getting a single line of text to wrap around the image. I'd really like to know if there is a way around this, and I looked pretty hard and found lots of people asking the same thing, and no positive answers. The only solutions I have seen involve only one line of text, or creating an HTML document on the fly and displaying it in a web view.
User avatar
jonw
Junior Developer
Junior Developer
 
Posts: 24
Joined: Wed Feb 10, 2010 9:00 pm
Location: London

Postby sanyiii » Fri Feb 12, 2010 6:40 am

I have tried the webview component, but it's not really good for me, because i want to load the image on the fly and i want to resize it before showing. And this will be only a small part of my activity's screen.
Is there a way to know the width of the characters? Certanly, i know the heigth of the chars, but how can i calculate the width of a character or a word?
sanyiii
Developer
Developer
 
Posts: 42
Joined: Wed Jun 10, 2009 9:58 am

Postby azraeal » Fri Feb 12, 2010 7:16 am

Sounds like you're giving this some good old fashioned elbow grease.

You can get the total width of your text if you're using the Canvas.drawText() method. Granted, you'd then have to implement your own custom view. The Paint object has a measureText() method that returns the text width in pixels. Make sure you do this after you've applied your text style(size, font, etc). Then, use this Paint object to draw the text with drawText() mentioned above.

You can draw by word, but it's easier to just do the whole text block at once with the following drawText method:
drawText(CharSequence text, int start, int end, float x, float y, Paint paint)
Draw the specified range of text, specified by start/end, with its origin at (x,y), in the specified Paint.

Go through your text block, find the max words that fit in one line, use drawText(), increment the Y, draw more text, rinse and repeat.

Not quite as simple as html/css floating images =/
azraeal
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Fri Sep 04, 2009 6:34 pm
Location: California

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Majestic-12 [Bot] and 9 guests