简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM