Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transparent circle with border

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> 
like image 500
Anirudh Avatar asked Apr 19 '13 06:04

Anirudh


People also ask

Can I download free circle png transparent images for my design?

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

Is there a way to make a dark background transparent?

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.

What exactly is a circle?

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...

How to get the color of transparent in Android?

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.


2 Answers

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)

like image 67
stinepike Avatar answered Oct 01 '22 13:10

stinepike


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> 
like image 36
anupam sharma Avatar answered Oct 01 '22 13:10

anupam sharma