gman
gman

Reputation: 1272

creating a circle surrounded by a rectangle drawable in android

I need to create a drawable for the following image.

enter image description here

I tried the following drawable

    <item>
        <shape android:shape="rectangle">
            <stroke android:width="3dp"
                android:color="#FF999999"/>
            <solid android:color="#00000000"/>
            <padding
                android:bottom="0dp"
                android:left="0dp"
                android:right="0dp"
                android:top="0dp" />
        </shape>
    </item>
    <item >
        <shape android:shape="oval">
            <solid android:color="@color/white"/>
            <size android:width="3dp"
                android:height="3dp"/>
        </shape>
    </item>



</layer-list>

But All I am getting is just the circle, I couldn't figure out how to bring up the rectangular border. where am I going wrong???

Upvotes: 0

Views: 2109

Answers (1)

Dhinakaran Thennarasu
Dhinakaran Thennarasu

Reputation: 3356

The item needs width and height as well. You also need to say the circle to be with the center gravity. Feel free to change the width/Colors too.

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item android:height="5dp" android:width="5dp" >
        <shape android:shape="rectangle">
            <stroke android:width="3dp"
                android:color="#FF999999"/>
            <solid android:color="#00000000"/>

        </shape>
    </item>
    <item  android:height="3dp" android:width="3dp" android:gravity="center">
        <shape android:shape="oval">
            <solid android:color="@android:color/white"/>
            <size android:width="3dp"
                android:height="3dp"/>
        </shape>
    </item>

</layer-list>

Upvotes: 1

Related Questions