Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ring shape in android

I have the following xml in drawable folder (circle_status.xml) to create a ring:

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="ring" android:innerRadius="15dp" android:thickness="10dp" android:useLevel="false">  <solid android:color="#ababf2" />  </shape> 

And insert the drawable like a background of a relativeLayout, as next:

<RelativeLayout         android:id="@+id/RelativeLayout_Status"         android:layout_width="100dp"         android:layout_height="100dp"         android:layout_alignParentRight="true"         android:layout_alignParentTop="true"         android:background="@drawable/circle_status" >     </RelativeLayout> 

The problem, is in the relativeLayout appear a circle not a ring.

like image 954
suanido Avatar asked Jun 20 '13 14:06

suanido


People also ask

How do you make a circle shape on android?

Create A Solid Circle Shape The property android:shape="oval" makes it a circular shape.

What is an android shape?

The <shape> element is where the shape of your drawable is defined and all its nested elements are defined. The android:shape attribute can hold four values: rectangle , oval , ring , or line . If you do not specify a value, it will be a rectangle by default.

What is stroke in shape android?

Sometimes you want an outline around your shape and to do that you can use the stroke tag. You can specify the width and color of the outline using android:width and android:color.

What is drawable shape android?

A ShapeDrawable takes a Shape object and manages its presence on the screen. If no Shape is given, then the ShapeDrawable will default to a RectShape . This object can be defined in an XML file with the <shape> element.


2 Answers

Note that a ring is an oval without a fill. Just with a stroke. And the view holding it, should be a perfect square.

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">  <stroke     android:width="1dp"     android:color="@color/blue" /> </shape> 

And the view holding it

<ImageView      android:layout_width="10dp"      android:layout_height="10dp"      android:src="@drawable/ring" /> 
like image 160
Reinherd Avatar answered Sep 20 '22 13:09

Reinherd


I answer myself.

It seems the problem is in the Graphical Layout Editor of Eclipse, the code works fine in a real device.

like image 44
suanido Avatar answered Sep 19 '22 13:09

suanido