CardView不会在RecyclerView内部投射阴影

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

我已经尝试了所有东西。我的清单是

 <application
        android:hardwareAccelerated="true" 

我的布局是:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="240dp"
    android:layout_height="200dp">
    <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="8dp"
        android:layout_above="@+id/tvName"
        сard_view:elevation="4dp"
        xmlns:сard_view="http://schemas.android.com/apk/res-auto"
        сard_view:cardUseCompatPadding="true"
        сard_view:cardCornerRadius="5dp">

        <ImageView
            android:id="@+id/ivPoster"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:adjustViewBounds="true"/>

    </androidx.cardview.widget.CardView>
    <TextView
        android:id="@+id/tvName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="bottom|center_horizontal"
        android:layout_alignParentBottom="true"
        android:minLines="1"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:textSize="16sp"
        android:layout_marginBottom="16dp"/>
</RelativeLayout>

因此,在具有网格布局的RecyclerView内,虽然它在Android Studio中显示为阴影,但在预览中显示了阴影,但未显示任何阴影

android android-recyclerview android-cardview
1个回答
0
投票

我认为这是因为在适配器中的ImageView上设置图像时,ImageView与cardview的阴影重叠。给图像视图一些余量和阴影将显示出来(但它会是难看的xD)。为了进行测试,我显示了Cardview的2个,但给出了第一个src。结果如下:enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.