I'm using card view for floating action button in android material design. I'm using following code for get the circle
<android.support.v7.widget.CardView
android:id="@+id/fab"
android:layout_width="38dp"
android:layout_height="38dp"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
card_view:background="@color/blue"
card_view:cardCornerRadius="19dp"
card_view:cardPreventCornerOverlap = "false"
card_view:cardElevation="6dp" >
</android.support.v7.widget.CardView>
I have set corner radius as half of width. but still I can't get the circle shape.
Yes, I have achieved it by reducing half of the CardCornerRadius to its View's Height.
I have solved the problem. Now android providing design library for material design, which has the FloatingActionButton. No need of customizing card view for floating action button.
Add design library in gradle dependencies
For more detail refer this link
card_layout.xml
MainActivity.java
first import the drawbleToolBox library in your project. with this library, you can create drawable dynamically.
if you are using cardview in your recycleview, getting the cardview widths doesn't work becuse it doesn't create yet. so you should do as below
To achieve a circular shape using Card view you can set the shape property, android:shape="ring".
app:cardCornerRadius should be set to half the width or height of the child view
I came up with simple Solution of Using a Drawable and it looks amazing!
Get Drawable here https://drive.google.com/open?id=0B4Vo_ku-aIKzUFFnUjYxYVRLaGc