I\'m trying to make a thumb for a seekbar for my app, and I want to have an inner circle surrounded by a different, larger (semi-transparent) outer circle. I\'m trying to us
I ended up here in search of drawing concentric circle found only answers with layer list approach so adding my answer with only using the shape
, I hope it will help someone.
<shape android:shape="oval">
<solid android:color="#FFF" />
<size
android:width="15dp"
android:height="15dp" />
<stroke
android:width="6dp"
android:color="#000" />
</shape>
And this is the outcome.
Just you have to use Shap
Attribute
xml code drawable
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
<stroke android:width="2dp" android:color="#B91969"/>
<size android:width="@dimen/dim_16dp" android:height="@dimen/dim_16dp" />
<solid android:color="#0f0" />
</shape>
Output
I managed to solve this by setting the width and height of the <item>
in the <layer-list>
. Probably not as best practise, but seem ok as was for background of icon in list view that had fixed dimensions.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- larger circle at the back -->
<item android:height="54dp" android:width="54dp" android:gravity="center">
<shape
android:shape="oval">
<solid
android:color="#0000FF"/>
<!-- thicker outer boarder -->
<stroke
android:width="2dp"
android:color="#000000"/>
</shape>
</item>
<!-- inner circle -->
<item android:height="40dp" android:width="40dp" android:gravity="center">
<shape
android:shape="oval" >
<solid
android:color="#00FF00"/>
<stroke
android:width="1dp"
android:color="#000000"/>
</shape>
</item>
</layer-list>
Hope below code snippet helps :)
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- larger circle at the back -->
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadius="0dp"
android:shape="ring"
android:thicknessRatio="2"
android:useLevel="false" >
<solid android:color="#FFFFFF" />
<stroke
android:width="1dp"
android:color="#000000" /></shape>
</item>
<!-- inner circle -->
<item >
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadius="0dp"
android:shape="ring"
android:thicknessRatio="2.1"
android:useLevel="false" >
<solid android:color="#000000" />
<stroke
android:width="1dp"
android:color="#FFFFFF" /></shape>
</item>
</layer-list>
hope it will help. This is drawable *.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="oval">
<padding
android:bottom="1dp"
android:left="1dip"
android:right="1dp"
android:top="1dp" />
<solid android:color="#000" />
</shape>
</item>
<item>
<shape android:shape="oval">
<padding
android:bottom="1dp"
android:left="1dip"
android:right="1dp"
android:top="1dp" />
<solid android:color="#EEE" />
</shape>
</item>
</layer-list>
this is a short version of Sean Barbeau's answer
<stroke
android:width="1dp"
android:color="@color/white" />
<solid android:color="@color/dark_blue" />
<size
android:width="14dp"
android:height="14dp" />