Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to repeat a pattern in the Custom view up-to boundaries?

i want to restrict the repeat pattern of a set of random small pattern's to a particular region. I am creating one object ( CustomView ) by using canvas, I have knowledge how to repeat a pattern on the layout using xml code.

<bitmap
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:src="@drawable/patterntwo"
  android:tileMode="repeat" />

this is not working for canvas.

I essentially want to use a bitmap as a background image for customview and would like to repeat the bitmap in both the X and Y directions of view.

look at this image

enter image description here

like image 852
RajaReddy PolamReddy Avatar asked Jul 04 '12 06:07

RajaReddy PolamReddy


1 Answers

Please try with this code:-

paint = new Paint(Paint.FILTER_BITMAP_FLAG);
Shader mShader1 = new BitmapShader(bitmap, Shader.TileMode.REPEAT,Shader.TileMode.REPEAT);
paint.setShader(mShader1);
like image 200
Kumar Shorav Avatar answered Oct 05 '22 23:10

Kumar Shorav