Android overlay textview over imageview example via xml in RelativeLayout

How to place textview text above imageview image without programmatically method.

TextView text can be easily replaceable above imageview image using layout xml file in relative layout. So here is the complete step by step tutorial for Android overlay textview over imageview example via xml.

android-project-download-code-button

Note : Put image inside drawable-hdpi folder.

drawable hdpi folder

Download sample image from below and copy into drawable-hdpi folder.

textview above image

Android overlay textview over imageview example via xml.

Code for MainActivity.java file.

 package com.textviewaboveimage_android_examples.com;

import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 }
}

Code for activity_main.xml layout file.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.textviewaboveimage_android_examples.com.MainActivity" >

 <ImageView
 android:id="@+id/imageView1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"
 android:layout_centerVertical="true"
 android:src="@drawable/textview_above_image" />

 <TextView
 android:id="@+id/textView1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignLeft="@+id/imageView1"
 android:layout_alignRight="@+id/imageView1"
 android:layout_centerVertical="true"
 android:text="TextView Text Above ImageView"
 android:textAppearance="?android:attr/textAppearanceLarge"
 android:gravity="center"
 android:textColor="#fdfcfc" />

</RelativeLayout>

Screenshot:

Android overlay textview over imageview example via xml

Click here to download Android overlay textview over imageview example via xml project.

Leave a Reply

Your email address will not be published. Required fields are marked *