Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define a circle shape in an Android XML drawable file?

I have some problems finding the documentation of the definitions of shapes in XML for Android. I would like to define a simple circle filled with a solid color in an XML File to include it into my layout files.

Sadly the Documentation on android.com does not cover the XML attributes of the Shape classes. I think I should use an ArcShape to draw a circle but there is no explanation on how to set the size, the color, or the angle needed to make a circle out of an Arc.

like image 624
Janusz Avatar asked Jul 06 '10 09:07

Janusz


People also ask

How do I make drawable circles in android?

Usage In Activity Layout Now we can use this shape in the same way we use drawables. Let's set it to android:src of the ImageView. The important thing that you have to notice is that i have given 100dp to both layout_width and layout_height because a circle should have same radius around the area.

What is shape in XML?

The Shape Drawable is an XML file that defines a geometric shape, including colors and gradients. This is used to create a complex shape that can then be attached as the background of a layout or a view on screen.


1 Answers

This is a simple circle as a drawable in Android.

<?xml version="1.0" encoding="utf-8"?> <shape     xmlns:android="http://schemas.android.com/apk/res/android"     android:shape="oval">     <solid         android:color="#666666"/>     <size         android:width="120dp"         android:height="120dp"/> </shape> 
like image 79
Arefin Avatar answered Oct 06 '22 05:10

Arefin