0

我正在遵循此处给出的答案Array of images stacked next to each other, using LayerDrawable.(Displaying multiple image in single imageview) 。我的图像尺寸为 38x38。

这是我的代码:

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);

但这就是发生的事情:层错位

有什么帮助吗?

4

1 回答 1

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);  
于 2014-09-04T21:01:08.337 回答