I have multiple drawables and want to combine it to one drawable (for example, 4 squares to create one big square, like Windows logo :)). How can I do this?
You can do that using a TableLayout
or some LinearLayout
s. However, if what you want is to create a single image to usin within a ImageView
you will have to create a Bitmap
manually; it is not hard:
Bitmap square1 = BitmapFactory.decodeResource(getResources(), R.drawable.square1);
Bitmap square2 = BitmapFactory.decodeResource(getResources(), R.drawable.square2);
Bitmap square3 = BitmapFactory.decodeResource(getResources(), R.drawable.square3);
Bitmap square4 = BitmapFactory.decodeResource(getResources(), R.drawable.square4);
Bitmap big = Bitmap.createBitmap(square1.getWidth() * 2, square1.getHeight() * 2, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(big);
canvas.drawBitmap(square1, 0, 0, null);
canvas.drawBitmap(square2, square1.getWidth(), 0, null);
canvas.drawBitmap(square3, 0, square1.getHeight(), null);
canvas.drawBitmap(square4, square1.getWidth(), square1.getHeight(), null);
I have not even compile the code above; I'm just showing you how it can be done. I'm also assuming you have square drawables all with the same dimensions. Notice that the bitmap called big
can be used wherever you want (e.g. ImageView.setImageBitmap()
).
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