Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cardBackgroundColor and cardCornerRadius not working in AndroidX

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

I've defined my layout as below:

<?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>

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

Here there's my layout preview:

cardview issue

like image 383
Nicola Gallazzi Avatar asked Dec 10 '22 02:12

Nicola Gallazzi


2 Answers

I removed this lines in my Manifest file and after that my cardviews are worked prefectly fine

android:hardwareAccelerated="false"

like image 119
Malith Ileperuma Avatar answered Jan 22 '23 01:01

Malith Ileperuma


Try modifying the CardView as:

<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="@dimen/retail_card_width"
        app:cardCornerRadius="@dimen/card_radius"
        app:cardBackgroundColor="@color/baseYellow"
        android:layout_height="@dimen/retail_card_height">
like image 26
Deˣ Avatar answered Jan 22 '23 02:01

Deˣ