Change top/right/bottom/left of item of layer-list programmatically

2.1k views Asked by At

I have a layer-list.xml

<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
    </item>
    <item
        android:id="+id/item_2"
        android:bottom="1dp"
        android:left="1dp"
        android:right="1dp"
        android:top="1dp">
        <shape android:shape="rectangle">
            <solid android:color="@android:color/white" />
        </shape>
    </item>
</layer-list>

Now I want to change some property of items like (top,right) at runtime. I able to change the color of the shape inside the item by

LayerDrawable layerDrawable = (LayerDrawable) v.getContext().getResources().getDrawable(R.drawable.layer_list);
GradientDrawable drawable2 = (GradientDrawable) layerDrawable.findDrawableByLayerId(R.id.item_2);
drawable2.setColor(strokeColor[0]); 

but I don't know how to change top,right. How can I change it?
Any help or suggestion would be great appreciated.

1

There are 1 answers

1
D.M. On