如何修复 CardView 角半径问题?

KOT*_*IAS 5 xml android android-layout

我正在使用下面的代码创建一个CardView带角的,但它保持矩形

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/cardview_id"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="5dp"
    android:clickable="true"
    android:focusable="true"
    android:foreground="?android:attr/selectableItemBackground"
    card_view:cardCornerRadius="6dp">
Run Code Online (Sandbox Code Playgroud)

更新:我的清单中有一个错误,我只是删除了这一行:

机器人:硬件加速=“假”

小智 7

我也有同样的问题。我发现的问题是...

        android:hardwareAccelerated="false"
Run Code Online (Sandbox Code Playgroud)

从清单中删除了这一行,问题为我解决了。


Thi*_*tes 3

我发现你的代码没有任何问题,但如果它不起作用。尝试添加这个:

    app:cardCornerRadius="@dimen/margin_small"
    app:cardElevation="@dimen/margin_small"
    app:cardUseCompatPadding="true"
Run Code Online (Sandbox Code Playgroud)

这对我来说效果很好。并确保您运行的 API 高于 21。