How to draw a perfect round button?

I want to draw a perfect circular button. I tried using the following code:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval" >
    <stroke 
        android:width="3dip"
        android:color="#065a32" />
    <corners android:radius="10dip"/>
      <solid android:color="#eaebec" />
</shape>

But I could only draw an oval shape, even if I change the parameter:

<stroke 
android:width="3dip"/>
<corners android:radius="10dip"/>

My screenshot:

enter image description here

I have already tried different links on this site, but none of them satisfy my need.

Edit:

My code for getView ():

public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        if (convertView == null) { 
            LayoutInflater vi = (LayoutInflater) mContext
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.calendar_item, null);

        }
view.setBackgroundResource(R.drawable.calendar_cell_clicked);
}
+4
source share
3 answers

use this xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >

  <solid
      android:color="#eaebec" />
</shape>

and in your layout where you set the background usage

        android:layout_width="50dp"
        android:layout_height="50dp"

or any other size you need a circle in.

+7
source

use this xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <solid android:color="#9F2200"/>
    <stroke android:width="2dp" android:color="#fff" />
</shape>

and in your layout

android:background="@drawable/button"
0
source

circular_button.xml

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

    <solid android:color="#ce2c2c" />

</shape>

, .

android:background="@drawable/circular_button"


Output

0
source

All Articles