Hello, i want to add a caption which looks like the default text below an app icon to the widget of my app. Is there any common way to achieve this?
A:
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="72dp"
android:layout_height="wrap_content"
android:text="@string/label"
android:drawableTop="@drawable/icon"
/>
Something like this should work. Using the drawableTop/Left/Right attributes will allow you to place an image above the label. A full list of attributes can be found here.
Another thing you could try is:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="72dp"
android:layout_height="wrap_content"
>
<TextView
android:text="@string/label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/background_shape"
android:id="@+id/text"
/>
<ImageView
android:src="@drawable/icon"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:layout_above="@id/text"
/>
</RelativeLayout>
kcoppock
2010-10-14 14:11:29
Nice, works fine. But is there any way to get the same background for the text? (grey, rounded corners)
Coxer
2010-10-14 14:23:15
I can't test it right now, but you could probably use a shape drawable with rounded corners, and do `android:background="@drawable/background"`. I'm not sure whether that would cover only the text, or also the image drawable above as well, though.
kcoppock
2010-10-14 14:36:09
i already tested that, it covers the image as well
Coxer
2010-10-14 14:56:34
I've added a new suggestion. Again, I can't test right now unfortunately. :( I'm not sure I have the right wording for scaleType (might be fit_center?)
kcoppock
2010-10-14 15:34:32
seems not to work that well
Coxer
2010-10-15 11:28:47
A:
Nice, works fine. But is there any way to get the same background for the text? (grey, rounded corners)
Coxer
2010-10-14 14:22:52