1

how can I create a triangle gap on the bottom of a cardview like this in android studio?

a cardview like this

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
Mohammad Mirdar
  • 56
  • 1
  • 11
  • https://www.journaldev.com/10024/android-recyclerview-android-cardview-example-tutorial refer this site – Kabilan Jul 09 '20 at 13:49
  • the link that you preferred is just about simple cardviews. the cardview that I want to create has a gap on the bottom of it. – Mohammad Mirdar Jul 09 '20 at 13:59

1 Answers1

2

You can use the TriangleEdgeTreatment included in the Material Components Library.

Just use a simple layout like:

    <com.google.android.material.card.MaterialCardView
        android:id="@+id/card"
        .../>

then apply the TriangleEdgeTreatment on the bottom edge:

    MaterialCardView cardView = findViewById(R.id.card);
    cardView.setShapeAppearanceModel(cardView.getShapeAppearanceModel().toBuilder()
            .setBottomEdge(new TriangleEdgeTreatment(40.f, true))
            .build());

enter image description here

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841