Home > database >  Big white spaces between items of recycler view?
Big white spaces between items of recycler view?

Time:08-08

when i add items to my recyclerview it always puts big white spaces between them (5 cm between items). I implemented the recyclerview just like my other recyclerviews but here it always adds these white spots.. Does anyone know how to fix it?

the recycler view is inside a Nestedscrollview but this doesn't have impact on spaces of this recylcerview.

<androidx.recyclerview.widget.RecyclerView
                android:id="@ id/recyclerview"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/cardView"
                android:clipToPadding="true"
                android:nestedScrollingEnabled="false"
                tools:listitem="@layout/txt" />

And here is my Code from activity:

recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setHasFixedSize(true);
recyclerView.setAdapter(adapter);

Here is my XML item code

    <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_marginTop="5dp"
            android:layout_marginBottom="5dp"
            android:layout_marginRight="15dp"
            android:layout_marginLeft="15dp"
            android:weightSum="100">

            <TextView
                android:id="@ id/name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="name"
                android:layout_gravity="left"
                android:gravity="left"/>

            <TextView
                android:id="@ id/time"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Uhrzeit"
                android:layout_marginLeft="10dp"/>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="100"
                android:layout_gravity="right"
                android:gravity="right">

                <ImageView
                    android:id="@ id/settings"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/ic_three_dots"
                    android:layout_gravity="right"/>
            </LinearLayout>

        </LinearLayout>

        <TextView
            android:id="@ id/content"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="text"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="15dp"
            android:layout_marginBottom="15dp"/>
        
    </LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

CodePudding user response:

Change the android:layout_height="match_parent" to android:layout_height="wrap_content" in the androidx.constraintlayout.widget.ConstraintLayout XML code of RecyclerView items

  • Related