Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Text over image

I have an imageView with an image, over that image I want to place a text. How can I achieve that?

like image 411
AndyAndroid Avatar asked Mar 09 '11 08:03

AndyAndroid


People also ask

What is a relative layout?

RelativeLayout is a view group that displays child views in relative positions. The position of each view can be specified as relative to sibling elements (such as to the left-of or below another view) or in positions relative to the parent RelativeLayout area (such as aligned to the bottom, left or center).


2 Answers

That is how I did it and it worked exactly as you asked for inside a RelativeLayout:

<RelativeLayout      xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/relativelayout"     android:layout_width="fill_parent"     android:layout_height="fill_parent" >      <ImageView         android:id="@+id/myImageView"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:src="@drawable/myImageSouce" />      <TextView         android:id="@+id/myImageViewText"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignLeft="@id/myImageView"         android:layout_alignTop="@id/myImageView"         android:layout_alignRight="@id/myImageView"         android:layout_alignBottom="@id/myImageView"         android:layout_margin="1dp"         android:gravity="center"         android:text="Hello"         android:textColor="#000000" />  </RelativeLayout> 
like image 181
Alesqui Avatar answered Sep 21 '22 20:09

Alesqui


You may want to take if from a diffrent side: It seems easier to have a TextView with a drawable on the background:

 <TextView             android:id="@+id/text"             android:background="@drawable/rounded_rectangle"             android:layout_width="wrap_content"             android:layout_height="wrap_content"         </TextView> 
like image 38
martar Avatar answered Sep 20 '22 20:09

martar