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;
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.
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With