Charan Pai
Charan Pai

Reputation: 2318

How to use findDrawableByLayerId in android?

I want to use setBounds() to a specific item in layer-list, which is used as a background for a button. But I am not able to get the LayerDrawable object to call findDrawableByLayerId().

Can anybody help to solve this ?

Upvotes: 0

Views: 2065

Answers (2)

Charan Pai
Charan Pai

Reputation: 2318

used this method to create on new layerdrawable :) I could no use findDrawableByLayerId() :(

@Override
public void setBackgroundDrawable(Drawable background) {
    Log.d("button","setting new background  ");
    Drawable[] layers = new Drawable[5];
    Resources resources = getResources();

    layers[0] = resources.getDrawable(R.drawable.outer_rectangle);
    layers[1] = resources.getDrawable(R.drawable.inner_rectangle);
    layers[2] = resources.getDrawable(R.drawable.upper_ovel);
    layers[3] = resources.getDrawable(R.drawable.gradient_fill);
    layers[4] = resources.getDrawable(R.drawable.lower_ovel);

    LayerDrawable layerDrawable = new LayerDrawable(layers);

    layerDrawable.setLayerInset(0, 0, 0, 0, 0);
    layerDrawable.setLayerInset(1, 3, 3, 3, 0);
    layerDrawable.setLayerInset(2, 3, 15, 3, 25);
    layerDrawable.setLayerInset(3, 3, 23, 3, 0);
    layerDrawable.setLayerInset(4, 4, 60, 4, -5);

    super.setBackgroundDrawable(layerDrawable);
}

Upvotes: 2

chen
chen

Reputation: 192

if you want to use findDrawableByLayerId(int id), you should do setId(int index, int id) at first, if not the id is always -1.

Upvotes: 1

Related Questions