title: Item of RecyclerView inside a ConstraintLayout does not occupy the full width of its parent
body: <p>I'm having a problem using a <code>RecyclerView</code> within a <code>ConstraintLayout</code>, and wanted to confirm that I'm not doing anything wrong before declaring it as a bug. Basically I've defined a <code>RecyclerView</code> inside a <code>ConstraintLayout</code>:</p>
  
  <pre><code>&lt;android.support.constraint.ConstraintLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  
      &lt;android.support.v7.widget.RecyclerView
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          app:layout_constraintTop_toTopOf="parent"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintLeft_toLeftOf="parent"
          app:layout_constraintRight_toRightOf="parent"
          android:id="@+id/list"/&gt;
  
  &lt;/android.support.constraint.ConstraintLayout&gt;
  </code></pre>
  
  <p>And I've defined its item which is a <code>TextView</code> within a <code>ConstraintLayout</code> (or any other <code>ViewGroup</code>):</p>
  
  <pre><code>&lt;android.support.constraint.ConstraintLayout
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="120dp"
      android:layout_margin="8dp"
      android:background="@color/colorAccent"&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Hello" /&gt;
  
  &lt;/android.support.constraint.ConstraintLayout&gt;
  </code></pre>
  
  <p>After using a simple adapter to bind some data to this RecyclerView, the output looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/bEebJ.png" rel="noreferrer"><img src="https://i.stack.imgur.com/bEebJ.png" alt="Initial scene"></a></p>
  
  <p>It seems that it gets it right in the next measure cycle, because scrolling down:</p>
  
  <p><a href="https://i.stack.imgur.com/gt88d.png" rel="noreferrer"><img src="https://i.stack.imgur.com/gt88d.png" alt="Scroll down fully"></a></p>
  
  <p>And then scrolling back up fixes the first two items whose widths I assume were recalculated:</p>
  
  <p><a href="https://i.stack.imgur.com/clT8G.png" rel="noreferrer"><img src="https://i.stack.imgur.com/clT8G.png" alt="Scroll back up"></a></p>
  
  <p>The <code>ConstraintLayout</code> around the item - which is supposed to take up the whole width of the view - instead seems to <code>wrap_content</code>. If this <code>ConstraintLayout</code>'s height is set to <code>wrap_content</code>, the issue goes away. If the <code>TextView</code> is removed, the issue goes away. And finally, if the <code>RecyclerView</code> is not enclosed within a <code>ConstraintLayout</code>, the issue goes away.</p>
  
  <p>Here's the adapter:</p>
  
  <pre><code>public class MyAdapter extends RecyclerView.Adapter&lt;MyAdapter.ViewHolder&gt; {
      private String[] mDataset;
  
      public static class ViewHolder extends RecyclerView.ViewHolder {
          public ViewGroup vg;
          public ViewHolder(ViewGroup v) {
              super(v);
              vg = v;
          }
      }
  
      public MyAdapter(String[] myDataset) {
          mDataset = myDataset;
      }
  
      @Override
      public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
                                                 int viewType) {
          ViewGroup v = (ViewGroup) LayoutInflater.from(parent.getContext())
              .inflate(R.layout.simple_item, parent, false);
          return new ViewHolder(v);
      }
  
      @Override
      public void onBindViewHolder(ViewHolder holder, int position) {
          // Do nothing
      }
  
      @Override
      public int getItemCount() {
          return mDataset.length;
      }
  }
  </code></pre>
  
  <p>And here's <code>build.gradle</code>:</p>
  
  <pre><code>apply plugin: 'com.android.application'
  
  android {
      compileSdkVersion 26
      buildToolsVersion "27.0.3"
      defaultConfig {
          applicationId "com.ibsplc.icargo.icoandroid.recyclerviewbugtest"
          minSdkVersion 21
          targetSdkVersion 26
          versionCode 1
          versionName "1.0"
          testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
      }
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
          }
      }
  }
  
  dependencies {
      compile fileTree(dir: 'libs', include: ['*.jar'])
      androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
          exclude group: 'com.android.support', module: 'support-annotations'
      })
      compile 'com.android.support:appcompat-v7:26'
      compile 'com.android.support:design:26.0.0'
      compile 'com.android.support.constraint:constraint-layout:1.0.2'
      compile 'com.android.support:recyclerview-v7:26.0.0'
      testCompile 'junit:junit:4.12'
  }
  </code></pre>
  
  <p><a href="https://github.com/rgovind92/recyclerview-bug" rel="noreferrer">Here</a>'s a complete example.</p>