CardView 在 RecyclerView 中未正确显示 [英] CardView is not showing properly in RecyclerView

查看:40
本文介绍了CardView 在 RecyclerView 中未正确显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在回收站视图中显示卡片视图.我已经在 gradle 文件中编译了卡片视图库,但问题是卡片视图没有显示没有高度和阴影,它显示的是简单的平面视图.

I want to show card view in recycler view. I have compiled card view library in gradle file but the problem is card view is not showing there is no elevation and shadow it is showing simple plain view.

这是我的 gradle 依赖项:

Here is my gradle dependencies:

implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0   

Row_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_marginTop="10dp">

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:cardElevation="3dp"
    app:cardBackgroundColor="#fff"
    app:cardCornerRadius="3dp"
    app:contentPadding="3dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <ImageView
            android:layout_width="150dp"
            android:layout_height="140dp"
            android:id="@+id/userPostBook"/>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15dp"
            android:layout_marginTop="20dp"
            android:id="@+id/userBookName"
            android:textSize="18sp"/>

        <Button
            android:layout_width="wrap_content"
            android:layout_height="30dp"
            android:paddingBottom="5dp"
            android:paddingRight="5dp"
            android:text="DELETE"
            android:id="@+id/delete"
            android:textColor="#fff"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:background="@drawable/delete_button"
            tools:ignore="HardcodedText"
            android:layout_alignParentEnd="true" />

        </RelativeLayout>

    </LinearLayout>

</android.support.v7.widget.CardView>

这是它在recyclerview中的显示方式:

This is how it is showing in recyclerview:

正如您在上面的屏幕截图中看到的,recyclerview 中没有显示卡片视图.有人请告诉我如何克服这个问题.任何帮助将不胜感激.

As you can see in above screenshot there is no card view is showing in recyclerview. Someone please let me know how can I overcome this issue. Any help would be appreciated.

谢谢

推荐答案

您需要在 CardView 中使用 app:cardUseCompatPadding="true"代码>

You need to use app:cardUseCompatPadding="true" in your CardView

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:cardElevation="3dp"
    app:cardUseCompatPadding="true"
    app:cardBackgroundColor="#fff"
    app:cardCornerRadius="3dp"
    app:contentPadding="3dp">

这篇关于CardView 在 RecyclerView 中未正确显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆