卡片视图不形成圆角半径

问题描述 投票:0回答:3

我有对话框片段,并为其设置了自定义视图。我想用圆角制作它,并使用 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>

结果:

android rounded-corners cardview
3个回答
0
投票

如果不起作用,请尝试将卡片视图放入 linerlayout 或相对布局中,尝试向 linerlayout 或relativelayout 添加一些填充。


0
投票

这是 Bcoz 卡片颜色与背景颜色相似。您只需要设置海拔即可。


0
投票

将以下代码添加到您的 CardView 中;

app:cardBackgroundColor="@android:color/transparent" 
© www.soinside.com 2019 - 2024. All rights reserved.