How to get round shape in Android

AndroidDrawableShape

Android Problem Overview


How would I achieve a round shape in Android, like below, through an Android shape drawable:

enter image description here

Android Solutions


Solution 1 - Android

You need to create a shape drawable in the drawable folder that looks something like:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >
    <gradient android:startColor="#FFFF0000" android:endColor="#80FF00FF"
        android:angle="270"/>
</shape>

(For this example I have saved the drawable as circle.xml and it will have a gradient fill)

Then in your layout you need to define a view and set the shape as the background:

<View android:layout_width="50dp"
    android:layout_height="50dp"
    android:background="@drawable/circle"/>

The View defines the size and dimensions of the shape.

Edit - Screenshots of the result of the code

Graphical View

Code Image

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAndroidDevView Question on Stackoverflow
Solution 1 - AndroidGraham SmithView Answer on Stackoverflow