Search code examples
androidandroid-shapeandroid-shapedrawable

how to make a shape like the picture below using a shape drawable?


I met a difficulty in Android programming, I want to make a shape like the picture "supposed.bmp" I uploaded. But I don't know how to do that, I only made one like "actual.bmp" I uploaded by the code below.

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <corners
        android:radius="10dp"/>

    <solid
        android:color="#199900"/>

    <size
        android:height="20dp"
        android:width="20dp"/>

    <stroke
        android:width="2dp"
        android:color="#004A00"/>
</shape>

please help me to correct the code above, thank you very much!


Solution

  • I hope this may help you:

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    
        <item xmlns:android="http://schemas.android.com/apk/res/android">
            <shape xmlns:android="http://schemas.android.com/apk/res/android"
                android:shape="oval">
                <solid
                    android:color="#ffffff"/>
    
                <size
                    android:height="20dp"
                    android:width="20dp"/>
    
                <stroke
                    android:width="10dp"
                    android:color="#004A00"/>
            </shape>
        </item>
    
        <item xmlns:android="http://schemas.android.com/apk/res/android"
            android:bottom="30dp"
            android:left="30dp"
            android:top="30dp"
            android:right="30dp">
            <shape xmlns:android="http://schemas.android.com/apk/res/android"
                android:shape="oval">
                <solid
                    android:color="#004A00"/>
    
                <size
                    android:height="20dp"
                    android:width="20dp"/>
            </shape>
        </item>
    
    </layer-list>
    

    Edited:

    You may avoid the size attribute.

    Increase or decrease top, bottom, right, left value to make the inner circle smaller or larger.