0

I'm doing a small application and am using a RecyclerView but when I emulate my application on API 19 I got small gap between the item, however if I run the same application on API 22 there is no gap (there is a screen at the end).

I'm using material design

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>

Here is the image, on the left is API 22 and on the right API 19

Biscuit
  • 4,840
  • 4
  • 26
  • 54
  • 1
    It highly likely that it has something to do with the fact that on anything below API 21 `CardViews` and basically images vs API > 21 they are rendered in real time. This has even more truth when looking at that you dont have a corner radius or a height to the card which is why it appears flat in the API 22 screenshot – tyczj Apr 10 '20 at 15:41
  • I removed the radius, I though using `MaterialCardView` was going to prevent that sort of downside. So there is no fix for this ? – Biscuit Apr 10 '20 at 15:47
  • No there is no fix for this because of the difference in how they are rendered, API's below 21 dont have the ability to render shadows and stuff in realtime which is why they are images in those api's. I guess you could make your own background but thats probably more effort than its worth – tyczj Apr 10 '20 at 15:50
  • Okay, I understand, well since I don't need any round corner or elevation from my item, I'll use a simple layout. Thanks for pointing out this particular operating mode – Biscuit Apr 10 '20 at 15:55

1 Answers1

0

For my application, I don't need to use CardView therefore I changed them for a LinearLayout.

You can check these post to know more about CardView and layout

Biscuit
  • 4,840
  • 4
  • 26
  • 54