0
我想畫一個形狀像我icon.xml編程,但我不能嵌入第二圈進入第一圈,這是我的代碼:如何以編程方式創建圖層列表可繪製?
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);
有什麼不對?
謝謝你提前