Recycler view item fill up entire recycler view height after upgrading support library from "23.1.1" to "23.2.1"
<p>Previously, I'm using the following old support libraries "23.1.1".</p>

<pre><code>compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:preference-v7:23.1.1'
compile 'com.android.support:preference-v14:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
</code></pre>

<p>It works pretty well. Here's how my <code>RecyclerView</code> looks like</p>

<p><a href="https://i.stack.imgur.com/MlscZ.png" rel="noreferrer"><img src="https://i.stack.imgur.com/MlscZ.png" alt="enter image description here"></a></p>

<p>Now, I wish to migrate to "23.2.1", due to some bug fixes done.</p>

<pre><code>compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:support-v4:23.2.1'
compile 'com.android.support:preference-v7:23.2.1'
compile 'com.android.support:preference-v14:23.2.1'
compile 'com.android.support:design:23.2.1'
compile 'com.android.support:recyclerview-v7:23.2.1'
</code></pre>

<p>However, suddenly, all my <code>RecyclerView</code> items, seem to fill up the <code>RecyclerView</code> entire height.</p>

<p><a href="https://i.stack.imgur.com/qRf6U.png" rel="noreferrer"><img src="https://i.stack.imgur.com/qRf6U.png" alt="enter image description here"></a></p>

<p><a href="https://i.stack.imgur.com/XWgoB.png" rel="noreferrer"><img src="https://i.stack.imgur.com/XWgoB.png" alt="enter image description here"></a></p>

<p>Here's the code snippet of my layout file : <a href="https://gist.github.com/yccheok/241a0d38d56305a1be24d09b54eb1600" rel="noreferrer">https://gist.github.com/yccheok/241a0d38d56305a1be24d09b54eb1600</a></p>

<p>What really puzzle me is that, although I'm using <code>"wrap_content"</code> in my recycler view item layout, it doesn't work as expected.</p>

<p>I don't use any custom layout manager for my <code>RecyclerView</code>.</p>

<p>From <a href="http://developer.android.com/tools/support-library/index.html" rel="noreferrer">http://developer.android.com/tools/support-library/index.html</a>, I realize 23.2.1 makes quite a number of changes on <code>RecyclerView</code> this time.</p>

<ul>
<li>Fixed bugs related to various measure-spec methods. (Issue 201856)</li>
<li>Reduced the lockdown period in which <code>RecyclerView</code> does not allow adapter changes while calculating a layout or scroll. (Issue 202046)</li>
<li>Fixed a crash when calling <code>notifyItemChanged()</code> on an item that is out of view. (Issue 202136)</li>
<li>Fixed a crash that occurs when <code>RecyclerView.LayoutManager</code> adds and removes a view in the same measurement pass. (Issue 193958)</li>
</ul>

<p>What I suspect most is <a href="https://code.google.com/p/android/issues/detail?id=201856" rel="noreferrer">https://code.google.com/p/android/issues/detail?id=201856</a> , as it involves changing <strong>various measure-spec methods</strong></p>

<p>So far, I try to reproduce the problem with a simple <code>RecyclerView</code> project, with 23.2.1 but failed! It doesn't have "item fills up the <code>RecyclerView</code> entire height" problem. My guess is that, my simple project doesn't simulate the complex layout structure of my production project. My production project is having the following layout</p>

<pre><code>&lt;Activity&gt;
    &lt;Fragment&gt;
        &lt;View Pager&gt;
            &lt;Fragment&gt;
                &lt;RecyclerView /&gt;
            &lt;/Fragment&gt;
        &lt;/View Pager&gt;
    &lt;/Fragment&gt;
&lt;/Activity&gt;
</code></pre>

<p>After debugging for few hours, I'm still cannot find root cause for such problem, any hint?</p>

<p>Thanks.</p>

<h2>What I had tried</h2>

<p>I had tried to change <code>RecyclerView</code> </p>

<p>from</p>

<pre><code>&lt;android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
</code></pre>

<p>to</p>

<pre><code>&lt;android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
</code></pre>

<p>It looks good initially. However, when you perform scrolling, thing doesn't work as expected : <a href="https://www.youtube.com/watch?v=U2EChFn6WkI" rel="noreferrer">https://www.youtube.com/watch?v=U2EChFn6WkI</a></p>

<h2>UPDATE: I finally figure out the root cause</h2>

<p>Is mistake at my side! Since I need to have different margin for the last row item, here's my adapter code.</p>

<pre><code>@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    final List&lt;TransactionSummary&gt; transactionSummaries = buyArray.transactionSummaries;

    if (position == transactionSummaries.size() - 1) {
        holder.itemView.setLayoutParams(lastLayoutParams);
    } else {
        holder.itemView.setLayoutParams(normalLayoutParams);
    }
</code></pre>

<p>Unfortunately, <code>lastLayoutParams</code> and <code>normalLayoutParams</code> is being initialized as</p>

<pre><code>    normalLayoutParams = new LinearLayout.LayoutParams(
        LinearLayout.LayoutParams.MATCH_PARENT,
        LinearLayout.LayoutParams.MATCH_PARENT
    );

    lastLayoutParams = new LinearLayout.LayoutParams(
        LinearLayout.LayoutParams.MATCH_PARENT,
        LinearLayout.LayoutParams.MATCH_PARENT
    );
</code></pre>

<p>Using <code>LinearLayout.LayoutParams.WRAP_CONTENT</code> solve the problem.</p>