I am trying to create a circle with only a border using XML in android:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" > <stroke android:width="1dp" android:color="#000000"/> </shape>
The code I've used is posted above. However, I get a solid disk and a not a ring. I would like to get the output using just XML and not canvas. What am i doing wrong?
Thanks.
EDIT: Got it to work thanks to the answer below. Heres my final code:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:innerRadius="0dp" android:shape="ring" android:thicknessRatio="1.9" android:useLevel="false" > <solid android:color="@android:color/transparent" /> <size android:width="100dp" android:height="100dp"/> <stroke android:width="1dp" android:color="#FFFFFF"/> </shape>
You can explore in this category and download free Circle PNG transparent images for your design flashlight. Different styles of Circle PNG images with high resolution are available. Upload your first copyrighted design. Get $5 designer coupon packs
I'm looking for a way to be able to make parts of the dark background transparent, so the image can be seen. One alternative: Use a radial gradient to create the overlay effect, that way you get the same effect without having to rely on any new and questionably-supported browser features.
The circle is simply a circular element with a border. All you have to do now is fiddle with sizes, colors and tranparency. For the fun of it I added some :hover effects...
You can use android inbuilt value for transparent as @android:color/transparent or use #0000 or #00000000 for above starting for 4 digit first was for alpha and in 8 digit value first two digit was for same as alpha.
Try something like this
<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="@android:color/transparent" /> <stroke android:width="2dp" android:color="@android:color/darker_gray" /> </shape>
Update: made android:thicknessRatio="2"
to give full circle (using Nexus 5 - Lollipop)
use this it will work
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" > <gradient android:centerX=".6" android:centerY=".40" android:endColor="@android:color/transparent" android:gradientRadius="20" android:startColor="@android:color/transparent" android:type="radial" /> <stroke android:width="1dp" android:color="#FFFFFF" /> <size android:height="100dp" android:width="100dp" /> </shape>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With