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 -
<?xml version="1.0" encoding="utf-8"?>
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 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
Constant Value Description
disabled
-1 Do not tile the bitmap. This is the default value.
clamp
0 Replicates the edge color.
repeat
1 Repeats the bitmap in both direction.
mirror
2 Repeats 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
Not Working, Please provide a Sample.
ReplyDeleteon android.developer20@gmail.com
...Perfetto. Grazie
ReplyDelete