I want to draw a shape like my icon.xml programmatically, but I can't embed the second circle into the first circle this is my code :
icon.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/ok">
<shape
android:shape="oval">
<solid android:color="#ffffff" />
<size android:width="33px" android:height="33px"/>
<stroke android:width="4px"
android:color="#ff0000"/>
<padding android:bottom="8px"
android:left="8px"
android:right="8px"
android:top="8px"/>
</shape>
</item>
<item>
<shape android:shape="oval">
<solid android:color="#ccff0000"/>
</shape>
</item>
</layer-list>
MainActivity.java
GradientDrawable layer1 = new GradientDrawable();
layer1.setShape(GradientDrawable.OVAL);
layer1.setSize(33,33);
layer1.setColor(Color.WHITE);
layer1.setStroke(4,Color.RED);
GradientDrawable layer2 = new GradientDrawable();
layer2.setShape(GradientDrawable.OVAL);
layer2.setColor(Color.BLUE);
InsetDrawable insetLayer2 = new InsetDrawable(layer1, 8, 8, 8, 8);
LayerDrawable layerDrawable = new LayerDrawable(new Drawable[]
{insetLayer2,layer2});
button.setBackground(layerDrawable);
What's wrong ?
thank you in advance
Finally I got the answer. My problem was how to set padding for out Circle,
however we can set padding programmatically using setLayerInset(int index, int l, int t, int r, int b)
for two gradients separately.