Spaceguy99
Spaceguy99

Reputation: 33

ReyclerView item list massive gaps between items

I have created a recyclerview layout. I have also created a relative layout to use as an item for the recycler view. However, there are gaps of one screen between each item in the recyclerview list.

I have tried changing the constraints and layout to even things out.

This is the XML file for the relative layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res  /android"
android:layout_width="match_parent" android:layout_height="match_parent">

<TextView
    android:id="@+id/DescriptionTextr"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Chore:"
    android:textSize="18sp" />

<TextView
    android:id="@+id/description_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="13dp"
    android:layout_toEndOf="@+id/DescriptionTextr"
    android:text="TextView"
    android:textSize="18sp" />

<TextView
    android:id="@+id/choretime"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/DescriptionTextr"
    android:layout_marginTop="12dp"
    android:text="Length to do chore:" />

<TextView
    android:id="@+id/length_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/description_text"
    android:layout_marginStart="13dp"
    android:layout_marginTop="13dp"
    android:layout_toEndOf="@+id/choretime"
    android:text="TextView" />

This is the output on the android device:

enter image description here

Upvotes: 0

Views: 64

Answers (2)

Akanshi Srivastava
Akanshi Srivastava

Reputation: 1500

Please try changing your layout_height to wrap_content.

  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" 
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/DescriptionTextr"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Chore:"
        android:textSize="18sp" />

    <TextView
        android:id="@+id/description_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="13dp"
        android:layout_toEndOf="@+id/DescriptionTextr"
        android:text="TextView"
        android:textSize="18sp" />

    <TextView
        android:id="@+id/choretime"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/DescriptionTextr"
        android:layout_marginTop="12dp"
        android:text="Length to do chore:" />

    <TextView
        android:id="@+id/length_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/description_text"
        android:layout_marginStart="13dp"
        android:layout_marginTop="13dp"
        android:layout_toEndOf="@+id/choretime"
        android:text="TextView" />

</RelativeLayout>

or you can give some static height or wrap_content with some padding/margin if you want a little bit of distance between items.

This should fix your issue. Right now, since it is match_parent, each item is taking the height of the screen.

Upvotes: 0

extmkv
extmkv

Reputation: 2045

In the root of your adapter layout make sure you're applying:

  • layout_height="wrap_content" for a Vertical RecycleView;
  • layout_width="wrap_content" for a Horizontal RecycleView;

In your case your adapter layour have a match_parent the view will have the size of the RecycleView.

Example:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

   ....
</RelativeLayout>

Upvotes: 1

Related Questions