Search This Blog

Mind freaker Stuff

Please Visit my new blog http://www.mindfreakerstuff.com for new articles related to web and mobile designing.

Thursday, January 12, 2012

How to Add repeat or tile background image : Android App

To Add repeat or tile background to Android Application

1) Add your Image to - "res/drawable" folder in Your Project or create folder with "drawable" name inside "res" folder this will applied to all ( drawable-hdpi, drawable-mdpi & drawable-ldpi)







2) Create XML file for Repeated or Tile background  Using the BitmapDrawable class in same folder












To Create XML file -
  • Rightclick "drawable" folder >> New >> Android XML File >> Select Bitmap >>  Save
  • Replace bg1 in "android:src="@drawable/bg1"" with your icon file name add missing attribute and Save.
  XML Code :

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

3) Add Folowing Line to Your Layout XML ie (main.XML or your any custom layout file where you want to add 
Repeated or Tile background
) 

android:background="@drawable/bg"

Thats it your Done !!!! :)
Note : if you want to add different resolution  images  to adrawable-hdpi, drawable-mdpi & drawable-ldpi, you'll need to add this bg.xml and bg.png file and the relevant images to each of these to allow this functionality in high, medium and low dpi  screen sizes. 
More Options

ConstantValueDescription
disabled-1Do not tile the bitmap. This is the default value.
clamp0Replicates the edge color.
repeat1Repeats the bitmap in both direction.
mirror2Repeats the shader's image horizontally and vertically, alternating mirror images so that adjacent images always seam.
This corresponds to the global attribute resource symbol tileMode.
For More  information Please 
visit
-Amey Raut

2 comments: