Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: BitmapDrawable.Draw(Canvas) Doesn't seem to work

I am trying to tile a 20x20 background onto my Custom View but for some reason I am unable too.

    BitmapDrawable background;
    background = new BitmapDrawable(BitmapFactory.decodeResource(getResources(), R.drawable.back));
    background.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
    background.draw(canvas);

Does anyone have an idea why it isn't working?

like image 623
Peter Avatar asked Feb 23 '11 11:02

Peter


1 Answers

You can use BitmapDrawable, but you have to set the bounds first so it knows how much tiling to do:

BitmapDrawable background;
background = new BitmapDrawable(BitmapFactory.decodeResource(getResources(),R.drawable.back));

//in this case, you want to tile the entire view
background.setBounds(0, 0, myView.getWidth(), myView.getHeight());

background.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
background.draw(canvas);
like image 178
SharkAlley Avatar answered Sep 22 '22 23:09

SharkAlley