我有对话框片段,并为其设置了自定义视图。我想用圆角制作它,并使用 CardView 来实现它,但对话框的形状仍然是矩形。这是我的看法:
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
app:cardCornerRadius="40dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/card_cl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="36dp">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/id_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:textSize="36sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:text="12" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
如果不起作用,请尝试将卡片视图放入 linerlayout 或相对布局中,尝试向 linerlayout 或relativelayout 添加一些填充。
这是 Bcoz 卡片颜色与背景颜色相似。您只需要设置海拔即可。
将以下代码添加到您的 CardView 中;
app:cardBackgroundColor="@android:color/transparent"