3

I have made an image by combining multiple images putting one over another Using LayerDrawable

But the final image is getting streched Here is my code for making a layerdrawable
Bitmap mainBitmap;

Resources r = getResources();
Drawable[] layers = new Drawable[10];

layers[0]=r.getDrawable(R.drawable.cloud);

layers[1] = r.getDrawable(fragment.resId1);

layers[2] = r.getDrawable(fragment.resId2);

layers[3] = r.getDrawable(fragment.resId3);

layers[4] = r.getDrawable(fragment.resId4);

layers[5] = r.getDrawable(fragment.resId5);

layers[6] = r.getDrawable(fragment.resId6);

layers[7] = r.getDrawable(fragment.resId7);

layers[8] = r.getDrawable(fragment.resId8);

layers[9] = r.getDrawable(fragment.resId9);
LayerDrawable layerDrawable = new LayerDrawable(layers);
int width = layerDrawable.getIntrinsicWidth();
int height = layerDrawable.getIntrinsicHeight();
mainBitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
Canvas canvas = new Canvas(mainBitmap);
layerDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
layerDrawable.draw(canvas);</p>

and Here is the resultant image that i get through this code </p>

https://i.stack.imgur.com/Vuga9.jpg

Is there anyone who can help me to shortout this?
Sandeep dhiman
  • 1,863
  • 2
  • 17
  • 22
  • set a gravity for each layer – pskink Jun 03 '15 at 06:13
  • @ pskink sir Here I am not using layer-list to make my drawable – Sandeep dhiman Jun 03 '15 at 06:45
  • yes i know, you are using `LayerDrawable` – pskink Jun 03 '15 at 06:59
  • @pskink can you please tell me how i can set the gravity of each layer in LayerDrawable in android as am not getting any clue for this . – Sandeep dhiman Jun 03 '15 at 07:20
  • see what kind of `Drawable`s you are passing to `LayerDrawable` constructor – pskink Jun 03 '15 at 07:25
  • @pskink sorry sir but I am not getting What you want to say exactly ,Here I am just putting a particular image to a particular layer from drawable folder and I am not getting any option to set the gravity of each layer in it. – Sandeep dhiman Jun 03 '15 at 07:43
  • `Drawable` is an abstract class, right? so layers[0], layers[1], etc is not an abstract Drawable object but one of Drawable's subclass, so take a look what concrete class it is – pskink Jun 03 '15 at 07:51

0 Answers0