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
3
Answers
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.
Make sure the
RecyclerView
haslayout_width
also set tomatch_parent
.Your activity_main.xml(or any layout that hosts recyclerview) should look like this.
And list_item.xml layout should be something like below: