Android-向卡片视图添加阴影

问题描述 投票:0回答:1

我正在尝试向我的卡片视图添加阴影,但是似乎没有任何作用,我尝试使用compatpadding,layout_margin和其他方法,但是似乎在背景中没有阴影。

这是我希望它看起来像的图像:enter image description here

这是我的卡查看页面的代码:

    <?xml version="1.0" encoding="utf-8"?>

<LinearLayout 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="wrap_content"
    android:layout_height="wrap_content"

    android:outlineProvider="paddedBounds">


    <androidx.cardview.widget.CardView
        android:id="@+id/cv_id"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:backgroundTint="@color/textColour"
        android:elevation="10dp"
        android:orientation="vertical"
        android:outlineProvider="paddedBounds"
        app:cardBackgroundColor="@android:color/transparent"
        app:cardCornerRadius="4dp"
        app:cardElevation="3dp"
        app:cardUseCompatPadding="true">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="35dp"
            android:backgroundTint="@color/textColour"
            android:orientation="vertical"
            android:outlineProvider="paddedBounds">

            <TextView
                android:id="@+id/product_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:elevation="2dp"
                android:paddingBottom="20dp"
                android:text=""
                android:textAlignment="center"
                android:textColor="@color/textColour"
                android:textSize="50dp"
                android:textStyle="bold" />

            <ImageView

                android:id="@+id/product_image"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:layout_below="@id/product_name"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="3dp"
                android:layout_marginRight="10dp"
                android:elevation="2dp"
                android:paddingBottom="20dp"
                android:scaleType="centerCrop"


                />

            <TextView
                android:id="@+id/product_price"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/product_image"
                android:elevation="2dp"
                android:paddingBottom="20dp"
                android:text=""
                android:textAlignment="center"
                android:textColor="@color/textColour"
                android:textSize="20dp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/product_description"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/product_price"
                android:layout_marginTop="2dp"
                android:elevation="2dp"
                android:paddingBottom="10dp"
                android:text=""
                android:textAlignment="center"
                android:textColor="@color/textColour"
                android:textSize="17sp"
                android:textStyle="bold" />
        </RelativeLayout>

    </androidx.cardview.widget.CardView>

</LinearLayout>
android android-cardview cardview
1个回答
0
投票

尝试使用hardwareAccelerated = true

<LinearLayout 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="wrap_content"
    android:layout_height="wrap_content"
    android:hardwareAccelerated = true /* added here */
    android:outlineProvider="paddedBounds">
© www.soinside.com 2019 - 2024. All rights reserved.