【问题标题】:Recyclerview gap between item API 19项目 API 19 之间的 Recyclerview 差距
【发布时间】:2020-04-10 15:34:49
【问题描述】:

我正在做一个小型应用程序并使用RecyclerView,但是当我在 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>

这里是image,左边是API 22,右边是API 19

【问题讨论】:

  • 这很可能与以下事实有关:在 API 21 CardViews 以及基本上图像与 API > 21 的任何内容上,它们都是实时渲染的。当您看到卡片没有圆角半径或高度时,这更加真实,这就是为什么它在 API 22 屏幕截图中显得平坦
  • 我删除了半径,尽管使用MaterialCardView 可以防止这种不利影响。所以没有办法解决这个问题?
  • 不,由于渲染方式不同,因此无法解决此问题,低于 21 的 API 无法实时渲染阴影和东西,这就是为什么它们是这些 api 中的图像。我想你可以制作自己的背景,但这可能比它的价值更多的努力
  • 好的,我明白了,因为我的项目不需要任何圆角或立面,我将使用简单的布局。感谢您指出这种特殊的操作模式

标签: android android-layout material-design


【解决方案1】:

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

您可以查看这些帖子以了解有关CardViewlayout 的更多信息

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-08
    • 2015-10-08
    • 2015-01-20
    • 2017-01-04
    • 1970-01-01
    • 2018-11-10
    相关资源
    最近更新 更多