title: Horizontal RecyclerView with items that have dynamic height
body: <p>So I need a horizontal RecyclerView. However, the items in them have dynamic heights based on what's returned from the backend.</p>
  <p>The RecyclerView and its items have the height of &quot;wrap_content&quot;</p>
  <p>The problem is if the first visible items in the RecyclerView are small, then when the user scrolls to the larger items, they appear cut off.</p>
  <p>Ideally, we want the RecyclerView to be large enough to hold the largest item in the group (but only the largest existing item... not the hypothetically largest item). The RecyclerView dynamically changing its height is also acceptable.</p>
  <p>I wrote an example app to illustrate the problem. In this app, we have a horizontal list. The first 33 items should show 1 line of text, while the next should show 3 lines of text, and the last 34 should show 2 lines. However, they all show 1 line, because the height of the RecyclerView doesn't change.</p>
  <p>I've tried calling requestLayout() on the RecyclerView (and on the TextView) from onBindViewHolder(), but it doesn't seem to do anything.</p>
  <p><strong>MainActivity</strong>:</p>
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      private RecyclerView mRecyclerView;
      private RecyclerView.Adapter mAdapter;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          mAdapter = createAdapter();
  
          mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
          mRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
          mRecyclerView.setAdapter(mAdapter);
      }
  
      private RecyclerView.Adapter&lt;ViewHolder&gt; createAdapter() {
          RecyclerView.Adapter adapter = new RecyclerView.Adapter&lt;ViewHolder&gt;() {
              @Override
              public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
                  View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item, parent, false);
                  return new ViewHolder(v);
              }
  
              @Override
              public void onBindViewHolder(ViewHolder holder, int position) {
                  if (position &lt; 33) {
                      holder.mText.setText(&quot;1 line&quot;);
                  } else if (position &gt; 66) {
                      holder.mText.setText(&quot;2 lines\n2 lines&quot;);
                  } else {
                      holder.mText.setText(&quot;3 lines\n3 lines\n3 lines&quot;);
                  }
              }
  
              @Override
              public int getItemCount() {
                  return 100;
              }
          };
          return adapter;
      }
  
      private static class ViewHolder extends RecyclerView.ViewHolder {
          TextView mText;
          public ViewHolder(View itemView) {
              super(itemView);
              mText = (TextView) itemView.findViewById(R.id.text);
          }
      }
  }
  </code></pre>
  <p><strong>activity_main.xml:</strong></p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;RelativeLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      android:id=&quot;@+id/activity_main&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      android:paddingBottom=&quot;@dimen/activity_vertical_margin&quot;
      android:paddingLeft=&quot;@dimen/activity_horizontal_margin&quot;
      android:paddingRight=&quot;@dimen/activity_horizontal_margin&quot;
      android:paddingTop=&quot;@dimen/activity_vertical_margin&quot;&gt;
  
      &lt;android.support.v7.widget.RecyclerView
          android:id=&quot;@+id/recycler_view&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot; /&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  <p><strong>item.xml</strong></p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      android:orientation=&quot;vertical&quot; android:layout_width=&quot;wrap_content&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:background=&quot;#888888&quot;&gt;
      &lt;TextView
          android:id=&quot;@+id/text&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:text=&quot;Hi&quot;
          android:textSize=&quot;30sp&quot; /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>