cardBackgroundColor和cardCornerRadius在AndroidX中不起作用 [英] cardBackgroundColor and cardCornerRadius not working in AndroidX

查看:351
本文介绍了cardBackgroundColor和cardCornerRadius在AndroidX中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AndroidX库来处理CardView角半径和背景颜色.

I'm struggling with CardView corner radius and background color with AndroidX libraries.

我的布局如下:

<?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"
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:layout_width="@dimen/retail_card_width"
        card_view:cardCornerRadius="@dimen/card_radius"
        card_view:cardBackgroundColor="@color/baseYellow"
        android:layout_height="@dimen/retail_card_height">
    <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        <ImageView android:layout_width="match_parent" android:layout_height="match_parent"
                   tools:src="@drawable/ic_fruit_1"
                   app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent"
                   app:layout_constraintStart_toStartOf="parent"
                   android:scaleType="fitEnd"
                   app:layout_constraintTop_toTopOf="parent"/>
        <ImageView
                android:id="@+id/ivRetailBrand"
                android:layout_width="@dimen/brand_icon_size"
                android:layout_height="@dimen/brand_icon_size"
                tools:src="@drawable/esselunga"
                android:layout_marginTop="@dimen/retail_brand_margin"
                android:background="@drawable/round_outline"
                app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toStartOf="parent"
                android:layout_marginStart="@dimen/retail_brand_margin"/>
    </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>

不幸的是,cardCornerRadiuscardBackgroundColor似乎都无法在我的布局上正常工作.我不知道我的问题是否取决于AndroidX库.

Unfortunately, neither cardCornerRadius nor cardBackgroundColor seem working on my layout. I can't understand if my issue depends on AndroidX libraries or not.

这是我的布局预览:

推荐答案

原来,问题是我正在将cardview androidx库与支持recyclerview库混合使用.一旦我用以下项目重建项目:

It turned out that the problem was I was mixing cardview androidx library with support recyclerview library. Once I rebuilt the project with:

implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'

一切都很好.

这篇关于cardBackgroundColor和cardCornerRadius在AndroidX中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆