Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different corner radius values for a MaterialCardView

Is is possible to have different values for each corner radius of a MaterialCardView? And if so how?

I tried something like the code below but it doesn't seem to have any effect

    float radius = getContext().getResources().getDimension(R.dimen.default_corner_radius);
    ShapePathModel leftShapePathModel = new ShapePathModel();
    leftShapePathModel.setTopLeftCorner(new RoundedCornerTreatment(radius));
    leftShapePathModel.setTopRightCorner(new RoundedCornerTreatment(radius));
    MaterialShapeDrawable bg = new MaterialShapeDrawable(leftShapePathModel);
    container.setBackground(bg);

where container is

@BindView(R.id.container) MaterialCardView container;
like image 678
Tudor S. Avatar asked Feb 14 '19 10:02

Tudor S.


People also ask

How do you define corner radius?

The corner radius is a measurement describing the curve on the corners of your labels. This is measured in millimetres and refers to the radius of the circle created if the curve was extended to create a full circle.

What is card elevation?

CardView is a new widget in Android that can be used to display any sort of data by providing a rounded corner layout along with a specific elevation. CardView is the view that can display views on top of each other. The main usage of CardView is that it helps to give a rich feel and look to the UI design.


1 Answers

Try This Also

     <style name="TopCornerCardview" parent="Widget.MaterialComponents.CardView">
        <item name="cornerFamily">rounded</item>
        <item name="cornerSizeTopRight">@dimen/dp25</item>
        <item name="cornerSizeTopLeft">@dimen/dp25</item>
        <item name="cornerSizeBottomRight">0dp</item>
        <item name="cornerSizeBottomLeft">0dp</item>
        <item name="contentPadding">0dp</item>
    </style>

    <com.google.android.material.card.MaterialCardView
            style="@style/TopCornerCardview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/TopCornerCardview"
            app:cardBackgroundColor="@color/colorAccent"
            app:cardUseCompatPadding="true">

>
<!--views here-->
</com.google.android.material.card.MaterialCardView>
like image 71
Mujahid Khan Avatar answered Sep 23 '22 03:09

Mujahid Khan