title: RecyclerView with horizontal GridLayoutManager adjusts its height to largest row
body: <p>I want to use <code>RecyclerView</code> with <code>GridLayoutManager</code> to achieve something like that:</p>
  
  <p><a href="https://i.stack.imgur.com/YIUuPl.png" rel="noreferrer"><img src="https://i.stack.imgur.com/YIUuPl.png" alt="Target"></a></p>
  
  <p>Here is <code>GridLayoutManager</code> with horizontal orientation and 2 rows. What's important for me here is that <code>RecyclerView</code> is set as <code>wrap_content</code>.</p>
  
  <p>So I tried to achieve my goal with such code:</p>
  
  <p><code>MainActivity.kt</code></p>
  
  <pre><code>class MainActivity : AppCompatActivity() {
  
      private val adapter = Adapter()
      private val layoutManager = GridLayoutManager(this, 2, RecyclerView.HORIZONTAL, false)
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_main)
  
          recyclerView.adapter = adapter
          recyclerView.layoutManager = layoutManager
  
          adapter.submitList(listOf(Unit, Unit, Unit, Unit))
      }
  }
  </code></pre>
  
  <p><code>Adapter.kt</code></p>
  
  <pre><code>class Adapter : ListAdapter&lt;Any, ItemHolder&gt;(DiffCallback()) {
  
      override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemHolder {
          val itemView = LayoutInflater.from(parent.context).inflate(viewType, parent, false)
          return ItemHolder(itemView)
      }
  
      override fun onBindViewHolder(holder: ItemHolder, position: Int) {
      }
  
      override fun getItemViewType(position: Int): Int {
          return when {
              position % 2 == 0 -&gt; R.layout.item_small
              else -&gt; R.layout.item_normal
          }
      }
  
      class DiffCallback : DiffUtil.ItemCallback&lt;Any&gt;() {
          override fun areItemsTheSame(oldItem: Any, newItem: Any) = false
          override fun areContentsTheSame(oldItem: Any, newItem: Any) = false
      }
  
      class ItemHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
  }
  </code></pre>
  
  <p><code>activity_main.xml</code></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;androidx.constraintlayout.widget.ConstraintLayout 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"
      tools:context=".MainActivity"&gt;
  
      &lt;androidx.recyclerview.widget.RecyclerView
          android:id="@+id/recyclerView"
          android:layout_width="0dp"
          android:layout_height="wrap_content"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent" /&gt;
  
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  </code></pre>
  
  <p><code>item_normal.xml</code></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="100dp"
      android:layout_height="100dp"
      android:layout_margin="8dp"
      android:background="@color/colorAccent" /&gt;
  </code></pre>
  
  <p><code>item_small.xml</code></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="100dp"
      android:layout_height="50dp"
      android:layout_margin="8dp"
      android:background="@color/colorAccent" /&gt;
  </code></pre>
  
  <p>Unfortunately as the result, each row stretches to the largest row in grid:</p>
  
  <p><a href="https://i.stack.imgur.com/SohPcl.png" rel="noreferrer"><img src="https://i.stack.imgur.com/SohPcl.png" alt="current"></a></p>
  
  <p>The question is how can I remove the spacing between first row and second row? Keep in mind that I have to have scrollable horizontal grid that its height depends on its content. And items have to have fixed size.</p>