I have an imageView with an image, over that image I want to place a text. How can I achieve that?
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).
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>
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With