skip to Main Content

I have a problem filling the entire screen in a reclycle view.

This is my xml code of the cardview and my view where the reclyclerview is:

CardView:

This is how it looks in the Ide Android studio:

Layout where the Reclycler view is:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/textAmount"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:padding="4dp"
        android:text="30"
        android:textSize="30sp" />

    <TextView
        android:id="@+id/textIdPerson"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:padding="4dp"
        android:text="30"
        android:textSize="30sp" />

    <TextView
        android:id="@+id/textId"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:padding="4dp"
        android:text="30"
        android:textSize="30sp" />

</LinearLayout>






<LinearLayout

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="4dp">
    <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="4dp"
        app:cardCornerRadius="4dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/textAmount"
                android:padding="8dp"
                android:text="ID"
                android:textSize="30sp"
                android:layout_weight="1"
                android:gravity="center"/>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/textIdPerson"
                android:padding="8dp"
                android:layout_weight="1"
                android:text="UserId"
                android:textSize="30sp"
                android:gravity="center"/>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/textId"
                android:padding="8dp"
                android:textSize="30sp"
                android:layout_weight="1"
                android:text="Amount"
                android:gravity="center"/>

        </LinearLayout>


    </androidx.cardview.widget.CardView>

    <androidx.recyclerview.widget.RecyclerView
        android:layout_gravity="center"

        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:id="@+id/recycler_view"
        android:nestedScrollingEnabled="false"
        tools:listitem="@layout/list_row_main"/>
    


</LinearLayout>

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:layout_alignParentBottom="true">


    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="atras"
        android:onClick="@{viewmodel::back}"
        android:layout_weight="1"
        android:layout_marginRight="4dp"/>
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Siguiente"
        android:onClick="@{viewmodel::next}"
        android:layout_weight="1"/>
</LinearLayout>

Image:
enter image description here

But when I start the application on the device it looks like this

enter image description here

3

Answers


  1. Check your adapter class, Layout you designed for adapter class should have width match parent and three different textviews with equal width to hold values.

    Login or Signup to reply.
  2. Make sure the RecyclerView has layout_width also set to match_parent.

    Login or Signup to reply.
  3. Your activity_main.xml(or any layout that hosts recyclerview) should look like this.

    <androidx.appcompat.widget.LinearLayoutCompat 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:orientation="vertical"
    >
    
    <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:layout_marginStart="5dp"
        android:layout_marginTop="10dp"
        android:layout_marginEnd="5dp"
        app:cardCornerRadius="5dp"
        app:cardElevation="8dp">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_gravity="center"
            android:gravity="center_vertical|center"
            android:orientation="horizontal">
    
            <TextView
                android:id="@+id/textAmount"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:padding="4dp"
                android:text="Amount"
                android:textSize="30sp" />
    
            <TextView
                android:id="@+id/textIdPerson"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:padding="4dp"
                android:text="UserID"
                android:textSize="30sp" />
    
            <TextView
                android:id="@+id/textId"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:padding="4dp"
                android:text="Id"
                android:textSize="30sp" />
        </LinearLayout>
    </androidx.cardview.widget.CardView>
    
    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_gravity="center"
        android:layout_marginBottom="8dp"
        android:layout_weight="2"
        android:nestedScrollingEnabled="false"
        tools:listitem="@layout/list_item" />
    
    <androidx.appcompat.widget.LinearLayoutCompat
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
    
        <Button
            android:id="@+id/btnAtras"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="5dp"
            android:layout_marginEnd="5dp"
            android:layout_marginBottom="5dp"
            android:layout_weight="1"
            android:text="ATRAS"
    
            />
    
        <Button
            android:id="@+id/btnSignature"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="5dp"
            android:layout_marginEnd="5dp"
            android:layout_marginBottom="5dp"
            android:layout_weight="1"
            android:text="Signature" />
    </androidx.appcompat.widget.LinearLayoutCompat>
    </androidx.appcompat.widget.LinearLayoutCompat>
    

    And list_item.xml layout should be something like below:

    <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="70dp"
    android:layout_marginTop="5dp"
    android:layout_marginBottom="5dp"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    
    <androidx.cardview.widget.CardView
        android:layout_width="0dp"
        android:layout_height="60dp"
        app:cardCornerRadius="5dp"
        app:cardElevation="8dp"
        android:layout_marginStart="5dp"
        android:layout_marginEnd="5dp"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp"
        app:cardUseCompatPadding="false"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        >
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:layout_gravity="center"
            android:gravity="center|center_vertical"
            >
            <TextView
                android:gravity="center"
                android:id="@+id/textAmount"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:layout_width="match_parent"
                android:padding="8dp"
                android:text="Amount"
                android:textSize="30sp" />
    
            <TextView
                android:gravity="center"
                android:id="@+id/textIdPerson"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:layout_width="match_parent"
                android:padding="8dp"
                android:text="UserId"
                android:textSize="30sp" />
    
            <TextView
                android:gravity="center"
                android:id="@+id/textId"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:layout_width="match_parent"
                android:padding="8dp"
                android:text="Id"
                android:textSize="30sp" />
        </LinearLayout>
    </androidx.cardview.widget.CardView>
    </androidx.constraintlayout.widget.ConstraintLayout>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search