Embed Text Inside Image
Solution 1:
There are a few ways to accomplish this.
The way I would do it is to make the image into a 9-patch. Either don't allow it to stretch, or mark areas outside of the character to stretch. In either case, use the right and bottom regions to mark where in the image you want the text to go.
Then you simply set the 9-patch as the background for a TextView
, and your text will be placed in the region you marked in the 9-patch.
An alternative method would be to use a RelativeLayout
with an ImageView
and a TextView
, then just position the TextView where you need it. However, I find dealing with trying to position views perfectly using this method to be tedious and error-prone. A 9-patch would also allow you to use this image with nearly any length of text without worrying about the text running outside the content region.
Solution 2:
You can set your image as the background of a layout, then add one or multiple textview(s) inside that layout and play around with the margins a bit until it fits
For example something looking like this:
<LinearLayoutandroid:background="@drawable/background"android:layout_width="fill_parent"android:layout_height="wrap_content" ><TextViewandroid:id="@+id/firstLine"android:layout_width="fill_parent"android:layout_height="wrap_content"android:gravity="center_vertical"android:textSize="16sp" /><TextViewandroid:id="@+id/secondLine"android:layout_width="fill_parent"android:layout_height="wrap_content"android:maxLines="2"android:textSize="12sp" /></LinearLayout>
Solution 3:
Well, as I suggested in comment earlier, put ImageView
and TextView
in RelativeLayout
, something like this (properties are random):
<RelativeLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><ImageViewandroid:id="@+id/Image"android:layout_width="50dp"android:layout_height="50dp"android:layout_alignParentLeft="true"android:layout_alignParentTop="true"android:layout_marginLeft="20dp"android:layout_weight="0"android:background="#ff1234"android:scaleType="centerCrop" /><TextViewandroid:id="@+id/name"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="10dp"android:layout_alignParentBottom="true"android:layout_alignParentRight="true"android:layout_below="@id/Image"android:layout_toRightOf="@id/Image"android:layout_weight="1"android:text="6363"android:background="#ff0034" /></RelativeLayout>
Post a Comment for "Embed Text Inside Image"