Why does the inner circle fill the outer circle?

心已入冬 提交于 2020-01-26 01:20:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!