androidandroid-cardviewmaterial-components-androidandroid-shape

how to create triangle gap on cardview?


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

a cardview like this


Solution

  • 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