Cardview,cardCornerRadius无效

6

我试图为我的卡片设置一个cardCornerRadius,但它没有起作用。

请看下面的代码:

CardView 是最后一个属性 cardCornerRadius

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/user_card_view"
    android:layout_width="match_parent"
    android:layout_height="@dimen/card_height"
    android:layout_gravity="center"
    android:layout_marginBottom="@dimen/md_keylines"
    android:layout_marginLeft="@dimen/md_keylines"
    android:layout_marginRight="@dimen/md_keylines"
    android:foreground="?attr/selectableItemBackground"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:cardCornerRadius="3dp">

依赖项

编译 'com.android.support:appcompat-v7:23.3.0' 编译 'com.android.support:design:23.3.0' 编译 'com.android.support:cardview-v7:23.3.0'

控制台没有显示任何错误信息,所以我真的不知道发生了什么。

你有什么好的想法吗?

谢谢!


你在使用哪些设备运行它?我认为它不会在安卓5.0以下的设备上工作。 - Rod_Algonquin
我已经在运行Lollipop的Nexus 5和Marshmallow的Nexus 6P上尝试过了@Rod_Algonquin。 - gon250
尝试移除前景。 - Tyler Pfaff
2个回答

27

我认为你的代码中可能正在使用setBackgroundColor

如果是这样,请尝试改用setCardBackgroundColor


好的回答。有没有关于它为什么会这样行为的解释? - shurrok

1
使用 card_view:cardCornerRadius="x"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接