Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw a perfect circular 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 was only able to 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 already tried different links of this site but none of them fulfill my need.

Edit:

My code for getView() is:

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);
}
like image 908
Madhav Bhattarai Avatar asked Dec 11 '13 04:12

Madhav Bhattarai


People also ask

How do you make a circle shape button?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/actiivity_main. xml. In the above code, we have taken the button with a round_button background.

How do you make a button a circle in CSS?

To create a rounded button you have to make use of the border-radius CSS property. The higher the value for that property the more rounder the corners will be. You can use any CSS unit for the boorder-radius property. It can be pixels, ems, rems, percentages etc.

How do you make a round edged button?

Rounded corners HTML Buttons You can make rounded corners button by adding border-radius of 5px to 10px on HTML buttons.

How do I make a circle button in HTML?

Use the border-radius Property to Create a Circle Button in CSS. We can use the border-radius property to create a circle button in CSS. The property creates the rounded corners to the selected element by adding the radius to the element's corners.


1 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 are setting background use

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

or whatever size you need the circle to be.

like image 66
rachit Avatar answered Sep 20 '22 22:09

rachit