Janneman96 Janneman96 - 4 months ago 22
Android Question

Why does the inner circle fill the outer circle?

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 Wrong xml But I want it to generate enter image description here
(the outer circles are the same size, this screenshot doesn't show it correctly)

Answer

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>

Comments