RecyclerView
Android
match_parent
layout issue
UI development

match_parent width does not work in RecyclerView

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

When match_parent seems not to work for a RecyclerView item, the problem is usually not the XML keyword itself. It is more often a measurement or inflation issue: the item view was inflated without the correct parent, the parent width is not exact, or the layout manager orientation makes the expectation invalid. Once you understand how RecyclerView measures children, the fix is usually straightforward.

Inflate The Item With The Parent

The single most common mistake is inflating the item layout with null as the parent.

Wrong:

kotlin
val view = LayoutInflater.from(parent.context)
    .inflate(R.layout.row_item, null)

Correct:

kotlin
val view = LayoutInflater.from(parent.context)
    .inflate(R.layout.row_item, parent, false)

RecyclerView needs the parent during inflation so the item's layout params are created with the right RecyclerView.LayoutParams. Without that, width behavior can be surprising, including match_parent appearing to do nothing.

Use The Right Width For The Right Orientation

In a vertically scrolling RecyclerView, an item root with android:layout_width="match_parent" is the normal choice.

xml
1<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2    android:layout_width="match_parent"
3    android:layout_height="wrap_content"
4    android:orientation="vertical">
5
6    <TextView
7        android:layout_width="match_parent"
8        android:layout_height="wrap_content"
9        android:text="Row" />
10</LinearLayout>

That works well because the parent width is usually known exactly.

But in a horizontally scrolling RecyclerView, match_parent width would mean each item wants the full width of the RecyclerView, which is often not what you intended. So orientation changes the meaning of the same XML.

Check The RecyclerView Itself

The parent RecyclerView must also have a real width to pass down.

xml
1<androidx.recyclerview.widget.RecyclerView
2    android:id="@+id/list"
3    android:layout_width="match_parent"
4    android:layout_height="match_parent" />

If the RecyclerView itself is inside a container with ambiguous measurement or wrap_content in a problematic hierarchy, the child cannot magically infer a correct full width.

This is especially common inside nested scrolling layouts, custom containers, or complex constraint setups.

ConstraintLayout And Nested Width Issues

If the row root is a ConstraintLayout, make sure the inner views are constrained correctly. Sometimes the row root is full width, but the content inside it is not, which makes it look as if match_parent failed.

For example, a child view inside ConstraintLayout usually needs start and end constraints instead of relying on width alone.

xml
1<TextView
2    android:id="@+id/title"
3    android:layout_width="0dp"
4    android:layout_height="wrap_content"
5    app:layout_constraintStart_toStartOf="parent"
6    app:layout_constraintEnd_toEndOf="parent"
7    app:layout_constraintTop_toTopOf="parent" />

Here 0dp with start and end constraints is the correct way to fill available width inside a ConstraintLayout.

Diagnose With Layout Inspector

If the XML looks right but the row still renders too narrow, inspect the actual runtime sizes. Android Studio's Layout Inspector or even a quick log of measured width can tell you whether the item root is narrow or only the inner content is.

That distinction matters. A full-width row containing a narrow child is a very different problem from a narrow row root.

Common Pitfalls

The most common mistake is inflating the row with inflate(layout, null) instead of inflate(layout, parent, false).

Another issue is expecting match_parent width to behave the same way in horizontal and vertical RecyclerView layouts. It does not.

It is also easy to blame the row root when the real problem is an unconstrained child inside a ConstraintLayout.

Finally, if the parent RecyclerView does not have a concrete width because of its own layout context, child items cannot reliably fill it.

Summary

  • In RecyclerView, match_parent width usually works when the row is inflated with the correct parent.
  • Always use inflate(layout, parent, false) in the adapter.
  • A vertical list and a horizontal list have different expectations for match_parent width.
  • Check the RecyclerView measurement and the inner child constraints, not only the row root.
  • Use Layout Inspector when the XML looks correct but runtime sizing still seems wrong.

Course illustration
Course illustration

All Rights Reserved.