Adrian Avram
Adrian Avram

Reputation: 957

Too much space in between CardViews

I have been having an issue with my card view where android studio is putting way too much space in between them. Here is an example screenshot I took from the emulator. For my layout inflater here is the code I used:

@Override
public DriveStatsViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType)
{
    View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.cardview_layout, viewGroup, false);
    DriveStatsViewHolder dsvh = new DriveStatsViewHolder(v);
    return  dsvh;
}

Below is my cardview_layout.xml

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

<android.support.v7.widget.CardView
    android:id="@+id/cv"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginTop="8dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintHorizontal_bias="1.0"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.0">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="16dp"
        >

        <TextView
            android:id="@+id/FinishTime"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/Drive_Date"
            android:layout_toStartOf="@+id/Total_Drive_Time"
            android:textAlignment="textEnd"
            android:textSize="18sp"
            tools:text="Finish Time"/>

        <TextView
            android:id="@+id/Total_Drive_Time"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentTop="true"
            android:textAlignment="viewStart"
            android:textSize="18sp"
            tools:text="Total Drive Time"/>

        <TextView
            android:id="@+id/Drive_Date"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:textSize="24sp"
            tools:text="Default Text"/>

        <TextView
            android:id="@+id/Start_Time"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/Drive_Date"
            android:textSize="18sp"
            tools:text="Start Time"/>

    </RelativeLayout>

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

I am pretty new to android studio so any help would be appreciated.

Upvotes: 0

Views: 694

Answers (1)

Ben P.
Ben P.

Reputation: 54244

Your outer RelativeLayout's height is match_parent, so each item in your list is as tall as your screen. However, the CardView itself only has a height of wrap_content, so most of that space is going to be left empty.

Upvotes: 2

Related Questions