Repeat background image in relativelayout android

How to revise relativelayout background image multiple times till filling the whole layout screen,if image is small in size.

Background image repetition is a simple type of effect which is activated when image in small size and dose not fill up the whole layout screen once. So image starts repeating itself with left to right form till the whole area on layout screen will no be fill completely using that image. On android applications by default repeating is disable but app developers can do this type of functionality using external custom layout xml file with android:tileMode=”repeat” attribute. So here is the complete step by step tutorial for Repeat background image in relativelayout android.

android-project-download-code-button

Note: Download background-image from below and put inside drawable-hdpi folder.

drawable hdpi folder

Here is the sample image:

background-image

How to Repeat background image in relativelayout android.

Code for MainActivity.java file.

package com.repeatbackgroundimagerelativelayout_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.repeatbackgroundimagerelativelayout_android_examples.com.MainActivity"
 android:background="@layout/repeat_background" >

</RelativeLayout>

Code for repeat_background.xml layout file.

 <?xml version="1.0" encoding="utf-8"?>
<bitmap
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:src="@drawable/background_image"
 android:tileMode="repeat"
 />

Screenshot :

Repeat background image in relativelayout androidClick here to download Repeat background image in relativelayout android project.

Leave a Reply

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