views:

33

answers:

2

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
Nice, works fine. But is there any way to get the same background for the text? (grey, rounded corners)
Coxer
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
i already tested that, it covers the image as well
Coxer
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
seems not to work that well
Coxer
A: 

Nice, works fine. But is there any way to get the same background for the text? (grey, rounded corners)

Coxer