i'm trying to create a circular CardView. But I don't know how to do it. Is there any attribute with which I can get a Circular CardView?.
The XML code is the following:
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view_outer"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_gravity="center"
card_view:cardBackgroundColor="@android:color/transparent"
card_view:cardCornerRadius="0dp"
card_view:cardElevation="3dp" >
</android.support.v7.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="10dp"
app:cardCornerRadius="100dp"/>
May be changing app:cardCornerRadius to half of the width and height.
OR May be Custom CardView
public class CircularCardView extends CardView {
public CircularCardView(@NonNull Context context) {
super(context);
}
public CircularCardView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public CircularCardView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = getMeasuredWidth();
setMeasuredDimension(width, width);
setRadius(width/2);
}
}
XML
<com.yourpackage.name.CircularCardView
android:layout_width="50dp"
android:layout_height="100dp"
android:layout_margin="10dp"
app:cardElevation="10dp"
/>