【问题标题】:CardView doesn't cast shadow inside RecyclerViewCardView 不会在 RecyclerView 内投射阴影
【发布时间】:2020-06-26 04:45:13
【问题描述】:

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

 <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 中显示它在预览中显示阴影

【问题讨论】:

  • 我试过你的布局,它似乎工作prntscr.com/rgaalw可能你有其他细节,导致问题
  • @MishaAkopov 因为你没有设置图片

标签: android android-recyclerview android-cardview


【解决方案1】:

我认为这是因为当您在适配器中的 ImageView 上设置图像时,ImageView 会重叠 cardview 的阴影。给图像视图一些边距和阴影将显示(但它会很丑 xD)。 为了测试,我显示了 2 个 Cardviewbut,但给出了第一个 src。结果如下:

如您所见,第一个没有阴影。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-20
    • 2017-12-12
    相关资源
    最近更新 更多