My usecase is to edit shapeAppearanceModel for com.google.android.material.card.MaterialCardView
card.shapeAppearanceModel = card.shapeAppearanceModel
.toBuilder()
.setTopEdge(TriangleEdgeTreatment(triangleSize))
.build()
Above code is working as expected But due to above programatically setup of shapeAppearanceModel
xml
<com.google.android.material.card.MaterialCardView
android:id="@+id/card"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardBackgroundColor="?myCustomColor"
app:cardCornerRadius="8dp"
app:cardElevation=4dp"
app:cardPreventCornerOverlap="true"
app:cardUseCompatPadding="false">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@drawable/myImageDrawable"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</com.google.android.material.card.MaterialCardView>
In Android studio as the TopEdge is define programatically Editor is not replicating the bug but in Emulator/Real device the child is not getting clipped and The Rounded Corners are getting overlapped by ImageView.
And when i remove the shapeAppearanceModel setup the clipping work's as expected.

The reason is Because
MaterialCardViewlockedclipToOutlinebehaviour only whe the Shape is Marked as Rounded and unfortunately, that implementation also locked by the component it self by default :here if you open MaterialCardView.java, you can find this code:
and if you go deeper, the implementation of
isRoundRect, would be like this :there's a condition to make it return true will be if the shape has the same or all corner rounded.
You can't trick that by programmatically set
card.setClipToOutline(true)because it happended after the render proses.The reason they make it that way because of some limitation by design :
(further reading : https://github.com/material-components/material-components-android/issues/1950)
The Good News you can solve that by creating your own
MaterialCardViewand override some implementation like this :I hope it can answer your question.