3 messages in com.googlegroups.android-beginnersHow to align image to text baseline?
FromSent OnAttachments
Ted Hopp27 Jan 2008 11:04 
Romain Guy27 Jan 2008 11:43 
Ted Hopp27 Jan 2008 12:05 
Subject:How to align image to text baseline?
From:Ted Hopp (t.@zigzagworld.com)
Date:01/27/2008 11:04:23 AM
List:com.googlegroups.android-beginners

I would like to have a view that combines an image with some text and have the bottom of the image be on the text baseline. I am using the following:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/ android" android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content">

<ImageView id="@+id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" />

<TextView id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>

I tried adding android:baselineAligned="true" to the LinearLayout, but that didn't work; the top of the image stayed aligned with the top of the text. Is there a different attribute I should use, or maybe a different container than LinearLayout?

A separate question: is imageView.setImageResource(-1); a good way to have an ImageView be empty (display no image and take up no space)? It seems to work, but I don't know if it may cause problems to set a