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?
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With