title: How can I use layout_weight in RecyclerView or ListView item view to have items of equal height fill up the available space on screen?
body: <p>I currently have a need to use a RecyclerView (or ListView) but the number of items is fixed at 4. I want those 4 items to equally use the available space on the screen. The RecyclerView is the only view on the screen except for the app bar. I.e. RecyclerView has <code>layout_height</code> set to <code>match_parent</code>. I chose the RecyclerView because the items have different layouts depending on model state.</p>
  
  <p>I haven't looked it up yet, but I'm sure I can set the height programmatically in Java code for each item. But that seems inelegant if I can specify it in the XML. Similar questions to my right, as I write this, answer that question.</p>
  
  <p>I've tried the following in the item_layout.xml file, the way <code>layout_weight</code> is used in other scenarios:</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_weight="1"
      android:layout_height="0dp"&gt;...&lt;/LinearLayout&gt;
  </code></pre>
  
  <p>But then nothing shows on screen. </p>
  
  <p>What I'd like to know is, <strong>can I do this in the layout XML with <code>layout_weight</code>, or something else? If so, how?</strong></p>