我正在為 recyclerview 行制作布局,我希望 ChipGroup 像在這個模型中一樣繪制 MaterialCard 的邊界:

問題是,無論我使用什么父布局,或者如果我禁用 clipChildren,芯片永遠不會與 MaterialCardView 重疊,如果我用一個簡單的按鈕替換芯片,它看起來正是我想要的。
<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>
這就是它的外觀(無論 ChipGroup 在 xml 中的 MaterialCardView 之前還是之后,如果我將它放在 MaterialCardView 中,它只會在里面繪制)。

這是用 Button 替換 ChipGroup,正如您所看到的,它繪制在 MaterialCardView 的邊界上,這正是我想要的。

uj5u.com熱心網友回復:
您可以使用高程。
源鏈接
https://material.io/design/environment/elevation.html#depicting-elevation
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/338290.html
標籤:安卓 材料设计 android-xml 安卓芯片
