问题
I'm trying to make a small dark circle within a large light circle using xml in Android. Both circles have a color, a size and a stroke. Why does the small dark circle fill the 50 dp instead of being 28dp?
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!--big light circle-->
<item>
<shape android:shape="oval">
<solid android:color="#EEEEEE" />
<size
android:width="50dp"
android:height="50dp" />
<stroke
android:width="2dp"
android:color="#404040" />
</shape>
</item>
<!--small dark circle-->
<item>
<shape android:shape="oval">
<solid android:color="#AEAEAE" />
<size
android:width="28dp"
android:height="28dp" />
<stroke
android:width="1dp"
android:color="#464646" />
</shape>
</item>
</layer-list>
The usage of the drawable:
<RadioButton
android:id="@+id/radioButtonPositive"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:button="@android:color/transparent"
android:drawableTop="@drawable/ic_choice_background"
android:gravity="center"
android:onClick="onRadioButtonClicked"
android:layout_marginRight="110dp"/>
The xml generates But I want it to generate (the outer circles are the same size, this screenshot doesn't show it correctly)
回答1:
Change to below
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!--big light circle-->
<item>
<shape android:shape="oval">
<solid android:color="#EEEEEE" />
<size
android:width="50dp"
android:height="50dp" />
<stroke
android:width="2dp"
android:color="#404040" />
</shape>
</item>
<!--small dark circle-->
<item android:bottom="11dp"
android:left="11dp"
android:right="11dp"
android:top="11dp">
<shape android:shape="oval">
<solid android:color="#AEAEAE" />
<stroke
android:width="1dp"
android:color="#464646" />
</shape>
</item>
来源:https://stackoverflow.com/questions/38672404/why-does-the-inner-circle-fill-the-outer-circle