我在使用 AndroidX 库时遇到 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"
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>
不幸的是,cardCornerRadius
和 cardBackgroundColor
似乎都不适合我的布局。我不明白我的问题是否取决于 AndroidX 库。
这是我的布局预览:
最佳答案
我在我的 Manifest 文件中删除了这一行,之后我的卡片 View 就可以正常工作了
android:hardwareAccelerated="false"
关于android - cardBackgroundColor 和 cardCornerRadius 在 AndroidX 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56835962/