简体   繁体   English

CardView 不会在 RecyclerView 内投射阴影

[英]CardView doesn't cast shadow inside RecyclerView

I've tried all the stuff.我已经尝试了所有的东西。 my manifest is我的清单是

 <application
        android:hardwareAccelerated="true" 

my layout is :我的布局是:

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

So, inside RecyclerView with grid layout doesn't show any shadow, although it shows it in Android Studio shows shadow in preview因此,在具有网格布局的 RecyclerView 中不显示任何阴影,尽管它在 Android Studio 中显示它在预览中显示阴影

I think it's because ImageView overlaps shadows of the cardview, when you set images on your ImageView in the adapter.我认为这是因为当您在适配器中的 ImageView 上设置图像时,ImageView 会重叠 cardview 的阴影。 Give the image view some margin and shadow will show (but it will be ugly xD).给图像视图一些边距和阴影会显示(但它会很难看 xD)。 For testing I display 2 of the Cardviewbut but gave first one src.为了测试,我显示了 Cardview 的 2 个,但给出了第一个 src。 here is the result:结果如下: 在此处输入图片说明

as you can see first one has no shadows.如您所见,第一个没有阴影。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM