How to set RecyclerView Max Height : <p>I want to set Max Height of RecylerView.I am able to set max height using below code.Below code makes height 60% of current screen.</p>

<pre><code>     DisplayMetrics displaymetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    int a = (displaymetrics.heightPixels * 60) / 100;
    recyclerview1.getLayoutParams().height = a;
</code></pre>

<p>But now problem is that, if it have no item then also its height is 60%.
So I want to set its height 0 when no item in it.</p>

<p>I want to achieve like something.</p>

<pre><code>    if(recyclerview's height &gt; maxHeight)
then set recyclerview's height to maxHeight
    else dont change the height of recyclerview.
</code></pre>

<p>How can i set it?
Please help me, I am stuck with it</p>
