Now it is possible, but only for phones with a version higher than or equal to 2.2 using the android.text.style.LeadingMarginSpan.LeadingMarginSpan2 interface, which is available in API 8.
Here is an article , but not in English, but you can download the sample source code directly from here .
If you want your application to be compatible with older devices, you can display a different layout without floating text. Here is an example:
Layout (the default for older versions will be changed programmatically for newer versions)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content"> <ImageView android:id="@+id/thumbnail_view" android:src="@drawable/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/message_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/thumbnail_view" android:textSize="18sp" android:text="@string/text" /> </RelativeLayout>
Helper Class
class FlowTextHelper { private static boolean mNewClassAvailable; static { if (Integer.parseInt(Build.VERSION.SDK) >= 8) {
MyLeadingMarginSpan2 class (updated to support API 21)
public class MyLeadingMarginSpan2 implements LeadingMarginSpan2 { private int margin; private int lines; private boolean wasDrawCalled = false; private int drawLineCount = 0; public MyLeadingMarginSpan2(int lines, int margin) { this.margin = margin; this.lines = lines; } @Override public int getLeadingMargin(boolean first) { boolean isFirstMargin = first;
Usage example
ImageView thumbnailView = (ImageView) findViewById(R.id.thumbnail_view); TextView messageView = (TextView) findViewById(R.id.message_view); String text = getString(R.string.text); Display display = getWindowManager().getDefaultDisplay(); FlowTextHelper.tryFlowText(text, thumbnailView, messageView, display);
This is what the application looks like on an Android 2.2 device: 
And this is for Android 2.1 device:

vortexwolf Dec 11 '11 at 10:09 2011-12-11 10:09
source share