首页 > 解决方案 > 项目 API 19 之间的 Recyclerview 差距

问题描述

我正在做一个小型应用程序并且正在使用 aRecyclerView但是当我在 API 19 上模拟我的应用程序时,项目之间的差距很小,但是如果我在 API 22 上运行相同的应用程序,则没有差距(最后有一个屏幕)。

我正在使用材料设计

frag_home 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:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/rv_videos"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        tools:listitem="@layout/item_video"
        />
</LinearLayout>

item_card xml

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/card"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:cardCornerRadius="0dp"
    app:cardPreventCornerOverlap="true">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <ImageView
            android:id="@+id/video_preview"
            android:layout_width="match_parent"
            android:layout_height="194dp"
            android:scaleType="centerCrop"
            tools:src="@drawable/img_error_v1"
            />
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:padding="16dp">
            <TextView
                android:id="@+id/video_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?attr/textAppearanceHeadline6"
                android:maxLines="1"
                tools:text="This is a really really really really really really really really really really really long title"
                />
            <TextView
                android:id="@+id/video_description"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="8dp"
                android:maxLines="1"
                android:textAppearance="?attr/textAppearanceBody2"
                android:textColor="?android:attr/textColorSecondary"
                tools:text="This is the URL for now"
                />
        </LinearLayout>
    </LinearLayout>
</com.google.android.material.card.MaterialCardView>

这是图像,左边是 API 22,右边是 API 19

标签: androidandroid-layoutmaterial-design

解决方案


对于我的应用程序,我不需要使用,CardView因此我将它们更改为LinearLayout.

您可以查看这些帖子以了解更多关于CardViewlayout


推荐阅读