title: How can I create a recyclerview child in a recycler parent with auto height
body: <p>I have tried many ways but still not found a suitable solution. We hope anyone can help us here. Thank you very much</p>
  
  <p>My Parent XML:</p>
  
  <pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:padding="16dp"
  tools:context="com.bbisno.quanlybaicatv2.ui.baicat.BaiCatFragment"&gt;
  
  &lt;!-- TODO: Update blank fragment layout --&gt;
  &lt;android.support.v7.widget.RecyclerView
      android:id="@+id/mRVBaiCat"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:scrollbars="vertical"&gt;
  
  &lt;/android.support.v7.widget.RecyclerView&gt;
  </code></pre>
  
  <p></p>
  
  <p>My Child XML :</p>
  
  <pre><code>&lt;android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:card_view="http://schemas.android.com/apk/res-auto"
      android:id="@+id/card_view"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_gravity="center"
      card_view:cardCornerRadius="4dp"&gt;
  
      &lt;RelativeLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:padding="16dp"&gt;
  
          &lt;ImageView
              android:id="@+id/imageView6"
              android:layout_width="24dp"
              android:layout_height="wrap_content"
              android:layout_alignParentStart="true"
              android:layout_alignParentTop="true"
              android:src="@drawable/ic_menu_baicat" /&gt;
  
          &lt;TextView
              android:id="@+id/tvTenBaiCat_baicat"
              android:layout_width="wrap_content"
              android:layout_height="48dp"
              android:layout_alignParentTop="true"
              android:layout_marginLeft="16dp"
              android:layout_toEndOf="@+id/imageView6"
              android:text="New Text"
              android:textAppearance="@style/TextAppearance.AppCompat.Body2" /&gt;
  
          &lt;Switch
              android:id="@+id/switch_baicat"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignParentEnd="true"
              android:layout_alignParentTop="true"
              android:checked="false" /&gt;
  
          &lt;ImageView
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_alignEnd="@+id/switch_baicat"
              android:layout_below="@+id/imageView6"
              android:src="@drawable/line_divider" /&gt;
  
          &lt;android.support.v7.widget.RecyclerView
              android:id="@+id/mRVListVatLieu_BaiCat"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:layout_alignParentStart="true"
              android:layout_below="@+id/tvTenBaiCat_baicat"&gt;
  
          &lt;/android.support.v7.widget.RecyclerView&gt;
      &lt;/RelativeLayout&gt;
  &lt;/android.support.v7.widget.CardView&gt;
  </code></pre>
  
  <p>My Parent Adapter:</p>
  
  <pre><code>public class BaiCatAdapter extends FirebaseRecyclerAdapter&lt;BaiCat, BaiCatAdapter.ViewHolder&gt; {
  private Context mContext;
  private ArrayList&lt;VatLieu&gt; listItemVLChild;
  private ListVLAdapterSimple listVLAdapterChild;
  
  
  public BaiCatAdapter(android.content.Context context, Class&lt;BaiCat&gt; modelClass, int modelLayout, Class&lt;ViewHolder&gt; viewHolderClass, Firebase ref) {
      super(modelClass, modelLayout, viewHolderClass, ref);
      this.mContext = context;
  
  
  }
  
  @Override
  protected void populateViewHolder(final BaiCatAdapter.ViewHolder viewHolder, BaiCat baiCat, int i) {
      System.out.println(baiCat.getTenBaiCat().toString());
  
      viewHolder.statusBC.setChecked(baiCat.isStatus());
      viewHolder.tvNameBC.setText("Bãi " + baiCat.getTenBaiCat().toString());
  
  
      listItemVLChild = new ArrayList&lt;VatLieu&gt;();
      listVLAdapterChild = new ListVLAdapterSimple(listItemVLChild);
  
      // lấy list giá của bãi cát
      Firebase mRef = new Firebase(Constant.REFBAICAT).child(baiCat.getTenBaiCat().toString()).child("listGiaBan/");
      //if != null là có list giá vật liệu
      mRef.addListenerForSingleValueEvent(new ValueEventListener() {
          @Override
          public void onDataChange(DataSnapshot dataSnapshot) {
              //kiem tra if có list giá vatlieu thì mới lấy data về
              if (dataSnapshot.hasChildren()) {
                  GenericTypeIndicator&lt;HashMap&lt;String, Object&gt;&gt; t = new GenericTypeIndicator&lt;HashMap&lt;String, Object&gt;&gt;() {
                  };
                  HashMap&lt;String, Object&gt; list = dataSnapshot.getValue(t);
                  Set&lt;Map.Entry&lt;String, Object&gt;&gt; entrySet = list.entrySet();
                  // duyệt qua các phần tử để lấy key giá vật liệu
  
                  for (Map.Entry entry : entrySet) {
                      System.out.println("Entry key: " + entry.getKey());
  
                      Firebase refGiaItem = new Firebase(Constant.REFVATLIEU).child(entry.getKey().toString());
                      refGiaItem.addListenerForSingleValueEvent(new ValueEventListener() {
                          @Override
                          public void onDataChange(DataSnapshot dataSnapshot) {
                              VatLieu vatLieu = dataSnapshot.getValue(VatLieu.class);
                              System.out.println("vatLieu: " + vatLieu.getGiaVL());
                              listItemVLChild.add(vatLieu);
                              listVLAdapterChild.notifyDataSetChanged();
  
                          }
  
                          @Override
                          public void onCancelled(FirebaseError firebaseError) {
  
                          }
                      });
  
                  }
  
  
              }
  
          }
  
          @Override
          public void onCancelled(FirebaseError firebaseError) {
  
          }
      });
  
      viewHolder.mRVListVatLieu.setAdapter(listVLAdapterChild);
      listVLAdapterChild.notifyDataSetChanged();
  
  }
  
  public static class ViewHolder extends RecyclerView.ViewHolder {
      //        View view;
      Switch statusBC;
      TextView tvNameBC;
      RecyclerView mRVListVatLieu;
  
      public ViewHolder(View itemView) {
          super(itemView);
  
          statusBC = (Switch) itemView.findViewById(R.id.switch_baicat);
          tvNameBC = (TextView) itemView.findViewById(R.id.tvTenBaiCat_baicat);
          mRVListVatLieu = (RecyclerView) itemView.findViewById(R.id.mRVListVatLieu_BaiCat);
          mRVListVatLieu.setHasFixedSize(false);
          RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(itemView.getContext(), LinearLayoutManager.VERTICAL, false);
          layoutManager.setAutoMeasureEnabled(true);
  
          mRVListVatLieu.setLayoutManager(layoutManager);
          mRVListVatLieu.addItemDecoration(new DividerItemDecoration(itemView.getContext(), RecyclerView.VERTICAL));
  
  
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>My Child Adapter:</p>
  
  <pre><code>public class ListVLAdapterSimple extends RecyclerView.Adapter&lt;ListVLAdapterSimple.ViewHolder&gt; {
  private List&lt;VatLieu&gt; listVLofBaiCat;
  
  public ListVLAdapterSimple(List&lt;VatLieu&gt; listVLofBaiCat) {
      this.listVLofBaiCat = listVLofBaiCat;
  }
  
  @Override
  public ListVLAdapterSimple.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
      View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_item_vatlieu,parent,false);
      ViewHolder vh = new ViewHolder(view);
      return vh;
  }
  
  @Override
  public void onBindViewHolder(ListVLAdapterSimple.ViewHolder holder, int position) {
      VatLieu vl = listVLofBaiCat.get(position);
      holder.tvsNameVl.setText(vl.getsNameVL());
      holder.tvlNameVl.setText(vl.getlNameVL());
      holder.tvGiaVl.setText(String.valueOf(vl.getGiaVL()));
      if(vl.isLaGiaBan()){
          holder.imgGiaVL.setImageResource(R.drawable.ic_ban);
      }else holder.imgGiaVL.setImageResource(R.drawable.ic_mua);
  
  
  }
  
  @Override
  public int getItemCount() {
      return listVLofBaiCat.size();
  }
  
  public class ViewHolder extends RecyclerView.ViewHolder{
      TextView tvsNameVl;
      TextView tvlNameVl;
      TextView tvGiaVl;
      ImageView imgGiaVL;
      Switch statusVL;
      public ViewHolder(View itemView) {
          super(itemView);
          tvsNameVl = (TextView) itemView.findViewById(R.id.tvSName_vatlieu);
          tvlNameVl= (TextView) itemView.findViewById(R.id.tvLName_vatlieu);
          tvGiaVl = (TextView) itemView.findViewById(R.id.tvGia_listvatlieu_addedit_baicat);
          imgGiaVL= (ImageView) itemView.findViewById(R.id.img_isGiaBan_vatlieu);
          statusVL = (Switch) itemView.findViewById(R.id.switch_listvatlieu_addedit_baicat);
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>When I set the cardview -> android:layout_height="match_parent" in child xml, I get this : </p>
  
  <p><a href="https://i.stack.imgur.com/IhEYh.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IhEYh.jpg" alt="Recyclerview not auto height"></a></p>
  
  <p>And when I set the child xml cardview -> android:layout_height="wrap_content", child item show wrong position and I get this :  </p>
  
  <p><a href="https://i.stack.imgur.com/xp7zB.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xp7zB.jpg" alt="Recyclerview auto height wrong"></a></p>
  
  <p>How to make the recyclerview child auto resize height? Somebody help me !</p>
  
  <p>I want to show the same interface same this photo :
  <a href="https://i.stack.imgur.com/nUjlq.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nUjlq.jpg" alt="Recyclerview show child item that I want"></a></p>