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. Socket in AsyncTask - application crashesso the UI won't be blocked

You can register a handler in your code and send message to update  your UI
component in Handler. I used this way to solve a similar problem like urs
before. For exapmpel

  if (socket.isConnected()) {
                                       OutputStreamOut = new
                                       InputStreamIn = new
                       // everything worked fine until here
                         //instead of doing this, send msg to a customized
                        //statusTxt.setText("App is now connected to:\n" +
IP + " : "
                        mHandler.sendEmptyMessage(UPDATE TEXT); //use
something like this
+ Port); // CRASHING !!!!
                               connected = true;
                       } else {


2. Delete Call Log entry Exception

hi guys,

i have a BroadCastReceiver which will listen to incoming calls. and
once the call is finish or users ignores the call i'm deleting the
number from the CallLog. i have tested this with HTC TATTOO and it
works fine there.

but when i tested this with Motorola MilesTone i'm getting a exception

this is the Exception

06-21 13:34:02.365: ERROR/DatabaseUtils(1337): Writing exception to
06-21 13:34:02.365: ERROR/DatabaseUtils(1337):
java.lang.UnsupportedOperationException: Cannot delete that URL:
06-21 13:34:02.365: ERROR/DatabaseUtils(1337):     at
06-21 13:34:02.365: ERROR/DatabaseUtils(1337):     at
06-21 13:34:02.365: ERROR/DatabaseUtils(1337):     at
06-21 13:34:02.365: ERROR/DatabaseUtils(1337):     at
06-21 13:34:02.365: ERROR/DatabaseUtils(1337):     at
dalvik.system.NativeStart.run(Native Method)

06-21 13:34:02.381: ERROR/AndroidRuntime(1593): Uncaught handler:
thread main exiting due to uncaught exception
06-21 13:34:02.459: ERROR/AndroidRuntime(1593):
java.lang.UnsupportedOperationException: Cannot delete that URL:

this is my code

public class CallListener extends BroadcastReceiver {
        private Context context;
        String phonenbr;
        TelephonyManager telManager;
        Handler handler = new Handler();

        public void onReceive(Context context, Intent intent) {
                // TODO Auto-generated method stub
                this.context = context;
                        telManager = (TelephonyManager) context
                        telManager.listen(new StateListener(),


        class StateListener extends PhoneStateListener {
                public void onCallStateChanged(int state, String 
incomingNumber) {
                        // TODO Auto-generated method stub
                        // super.onCallStateChanged(state, incomingNumber);
                        switch (state) {
                        case TelephonyManager.CALL_STATE_RINGING:
                        case TelephonyManager.CALL_STATE_IDLE:

                        case TelephonyManager.CALL_STATE_OFFHOOK:

protected void listeneNativeInbox() {

                                CallLog.Calls.CONTENT_URI, true, new 

                // Uri Sms = Uri.parse("content://sms/inbox");
                 * Cursor c = context.getContentResolver().query(
                 * CallLog.Calls.CONTENT_URI, null, null, null, null);

        class MyInboxListener extends ContentObserver {

                public MyInboxListener(Handler handler) {
                        // TODO Auto-generated constructor stub

                public boolean deliverSelfNotifications() {
                        // TODO Auto-generated method stub
                        return false;

                public void onChange(boolean selfChange) {
                        // TODO Auto-generated method stub
                        boolean b = false;
                        Uri books = 
                        Log.d("Authority", books.getAuthority());
                        Cursor cursor = 
context.getContentResolver().query(books, null,
                                        "Mobile" + "='" + phonenbr + "'", null,
                                        "category " + "DESC");
                        if (cursor != null) {
                                if (cursor.moveToNext()) {
                                        b = true;
                        Message msg = new Message();
                        msg.obj = "xxxxxxxxxx";
                        Cursor cur = context.getContentResolver().query(
                                        CallLog.Calls.CONTENT_URI, null, null, 
                                        CallLog.Calls._ID + " DESC");
                        long threadIdIn = cur
                        Uri uri = 
                        if (b) {
                                int x = 
context.getContentResolver().delete(uri, null, null);
                        // }

so do you have any idea about this??
NOTE:- works correctly in HTC tattoo but not in Motorola Milestone



3. Howto pass pointer to char parameter to kernel via copy_to_user()

4. HTC tattoo List separators and menu separator lines are not visible

5. HTC tattoo List separators and menu separator lines are not visible

6. Added Interface of is not resolving at runtime

7. URL links are not opened in HTML viewer