0

I am making the layout for a recyclerview row, and I want ChipGroup to draw over the border of the MaterialCard like in this mockup:

Mockup

The problem is that it doesnt matter what parent layout I use, or if I disable clipChildren, the chips never overlap the MaterialCardView, if I replace the chips with a simple button it looks exactly how I want it to.

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <com.google.android.material.chip.ChipGroup
        app:layout_constraintTop_toTopOf="parent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="10dp"
        app:singleLine="true">

        <com.google.android.material.chip.Chip
            android:id="@+id/chip_1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="false"
            android:text="Urgente"
            app:chipIcon="@drawable/ic_baseline_circle_24"
            app:chipIconSize="16dp"
            app:chipIconTint="@android:color/holo_orange_dark"
            app:chipStartPadding="6dp" />

        <com.google.android.material.chip.Chip
            android:id="@+id/chip_2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Etiqueta 1" />

        <com.google.android.material.chip.Chip
            android:id="@+id/chip_3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Etiqueta 2" />

    </com.google.android.material.chip.ChipGroup>
    <com.google.android.material.card.MaterialCardView
        android:layout_width="match_parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_height="72dp"
        android:layout_marginTop="22dp"
        app:cardCornerRadius="0dp"
        app:strokeColor="@android:color/holo_red_light"
        app:strokeWidth="2dp"/>

</androidx.constraintlayout.widget.ConstraintLayout>

This is how it looks (It doesnt matter if the ChipGroup is before or after the MaterialCardView in the xml, if I put it inside the MaterialCardView it only draws inside).

enter image description here

And this is replacing the ChipGroup with a Button, as you can see it draws over the border of the MaterialCardView, which is exactly what I want. enter image description here

dariovaz
  • 31
  • 4
  • MaterialCardView has a default elevation of around 2-4dp so you can either make the cardElevation 0dp or increase the elevation for the chipGroup to 4dp or above. The thing to note here is giving elevation to chipGroup will result in shadow displayed below each chip. Do note elevation will be applied for API Levels above 21. – Kartik Oct 27 '21 at 10:39
  • 1
    This has probably changed, Im targetting api 31 and setting CardView's elevation 0dp doesnt work, also the chips dont display shadow with 2dp of elevation in the chipgroup, which is enought for them to draw over the MaterialCardView – dariovaz Oct 27 '21 at 10:48

1 Answers1

1

You can use elevation.

Source Link

https://material.io/design/environment/elevation.html#depicting-elevation

Arda Kazancı
  • 8,341
  • 4
  • 28
  • 50