2

Need to draw the following circle , with the red colour shape using xml.

enter image description here

Is it possible to draw this using xml only?

dev
  • 1,085
  • 4
  • 19
  • 26

3 Answers3

4

You can make circle using the following XML code:

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >
<solid android:color="#c4bfbf"/>
</shape>

You can add the above circle as the background to a view, and on top of that view you could keep another view, which could be center vertical, and it's XML would be:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle" >
    <solid android:color="#FF0000"  />
    <padding android:bottom="1dp" android:left="10dp" android:right="10dp" android:top="1dp"/>
    <corners
        android:bottomRightRadius="20dp"
        android:bottomLeftRadius="20dp"
        android:topLeftRadius="20dp"
        android:topRightRadius="20dp"/>
</shape>
Eric B.
  • 4,622
  • 2
  • 18
  • 33
  • can you help me out here [http://stackoverflow.com/questions/43412704/how-to-draw-a-dot-circle-inside-a-square-drawable-in-android](http://stackoverflow.com/questions/43412704/how-to-draw-a-dot-circle-inside-a-square-drawable-in-android) – Siddarth G Apr 18 '17 at 07:47
0

to draw circle programmatically you can use this way,this worked for me

ShapeDrawable biggerCircle= new ShapeDrawable( new OvalShape());
                biggerCircle.setIntrinsicHeight( 60 );
                biggerCircle.setIntrinsicWidth( 60);
                biggerCircle.setBounds(new Rect(30, 30, 30, 30));
                biggerCircle.getPaint().setColor(Color.parseColor(first));//give any color here
                holder.firstcolor.setBackgroundDrawable(biggerCircle); 
Aditya Vyas-Lakhan
  • 13,409
  • 16
  • 61
  • 96
0

I have create the similar shape where an outer gray circle contains red circle inside. Here is the code:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >
<solid android:color="#E84F3D" />
<stroke
    android:width="15dp"
    android:color="#BEBEBE" />

</shape>
Rohit Sharma
  • 2,017
  • 1
  • 20
  • 22