0

I am following the answer given here Array of images stacked next to each other, using LayerDrawable.(Displaying multiple image in single imageview) . My images are 38x38 sized.

This is my code:

Drawable[] layers = new Drawable[2];
layers[0]=cActivity.getResources().getDrawable(R.drawable.white_pawn);
layers[1]=cActivity.getResources().getDrawable(R.drawable.black_pawn);

LayerDrawable pawns = new LayerDrawable(layers);
pawns.setLayerInset(0, 0, 0, 42, 0);
pawns.setLayerInset(1, 42, 0, 42, 0);
((ImageView)v.findViewById(R.id.baseImage)).setImageDrawable(pawns);

But that's what happens: layers misplaced

Any help?

Community
  • 1
  • 1
Ssr1369
  • 348
  • 3
  • 16

1 Answers1

0

The only difference with the question you are referring is that you are not setting the gravity for drawables. IIRC Drawables by default try to fill the the layer.

    layers[0].setGravity(Gravity.LEFT);
    layers[1].setGravity(Gravity.LEFT);  
user3811368
  • 183
  • 5
  • Ok, you are right, just tried, it works, ty! The thing's that the method setGravity is not available for Drawables, that's why I was forced to use BitMap Drawable, which I wanted to avoid simply because it seem to work without it. But you are right, ty very much sir! – Ssr1369 Sep 05 '14 at 23:12