I want to achieve this:
So I thought I could use a MaterialShapeDrawable to apply that transformation:
binding.card.background = MaterialShapeDrawable(
ShapeAppearanceModel.builder()
.setAllCornerSizes(5.dpToPx().toFloat())
.setTopEdge(object : TriangleEdgeTreatment(7.dpToPx().toFloat(), false){
override fun getEdgePath(length: Float, center: Float, interpolation: Float, shapePath: ShapePath) {
super.getEdgePath(length, 12.dpToPx().toFloat(), interpolation, shapePath)
}
})
.build()
).apply {
fillColor = resourcesProvider().colorStateListFromAttr(R.attr.colorSurface, R.style.App_CardView)
}
But unfortunately it changes nothing. So I've tried to apply to a direct children like this:
<com.google.android.material.card.MaterialCardView
style="@style/Widget.MaterialComponents.CardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="20dp"
android:clipChildren="false"
app:cardBackgroundColor="@android:color/transparent"
app:cardElevation="10dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginTop="10dp"> //without this margin nothing is shown
And it kinda works but I get a funky result due to app:cardElevation="10dp" (which is needed):
So my questions are:
1 - Is it possible to apply transformations to a CardView? if so, how?
2 - How can I solve this "shadow on top" problem?
Thanks.



