Android CardView不会在RecyclerView中投射阴影
我都试过了。 我的舱单是Android CardView不会在RecyclerView中投射阴影,android,android-recyclerview,android-cardview,Android,Android Recyclerview,Android Cardview,我都试过了。 我的舱单是 <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:
<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中显示,但在预览中显示阴影我认为这是因为当您在适配器的ImageView上设置图像时,ImageView与cardview的阴影重叠。给图像视图一些边距和阴影将显示,但它将是丑陋的xD。 对于测试,我显示了CardView2,但给出了第一个src。结果如下:
正如您所看到的,第一个没有阴影。我尝试过您的布局,它似乎可以工作,可能您有其他细节,导致problem@MishaAkopov因为你没有设置图像