title: recyclerview inside nestedscrollview loading slow
body: <p>I have recyclerview inside my nestedscrollview, when my recyclerview loads, I have no problem with scrolling, its very smooth but its loading very slow at first (its not about my data or networking) slow line is <code>recyclerview.adapter = MyAdapter()</code></p>
  
  <p>when I move the recyclerview out of nestedscrollview (first child of root element) its really fast. here is my xml</p>
  
  <p>with this xml it blocks the ui for 3-4 seconds and loads it but if I place my recyclerview outside of nestedscrollview it loads in milliseconds, unnoticable.</p>
  
  <p>I need the recyclerview in my nestedscrollview.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;layout xmlns:tools="http://schemas.android.com/tools" 
          xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:app="http://schemas.android.com/apk/res-auto"&gt;
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:focusableInTouchMode="true"
          android:background="#f7f7f7"
          android:orientation="vertical"&gt;
          &lt;androidx.appcompat.widget.Toolbar
              android:id="@+id/toolbar"
              android:layout_width="match_parent"
              android:layout_height="?attr/actionBarSize"
              app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
              app:titleTextAppearance="@style/ToolbarExpandedTextAppearance"
              app:layout_collapseMode="pin"
              android:background="@color/colorPrimary"&gt;
              &lt;ImageButton
                  android:layout_width="?attr/actionBarSize"
                  android:layout_height="?attr/actionBarSize"
                  android:id="@+id/right_button"
                  android:src="@drawable/ic_top_question"
                  android:layout_gravity="end|top"
                  android:contentDescription="@string/placeholder_right_button"
                  android:background="?attr/selectableItemBackground"/&gt;
          &lt;/androidx.appcompat.widget.Toolbar&gt;
  
          &lt;androidx.core.widget.NestedScrollView
              android:id="@+id/nestedScrollView"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:fillViewport="true"
              app:layout_behavior="@string/appbar_scrolling_view_behavior"
              android:orientation="vertical"&gt;
  
              &lt;androidx.constraintlayout.widget.ConstraintLayout
                  android:layout_width="match_parent"
                  android:orientation="vertical"
                  android:layout_height="match_parent"&gt;
  
                  &lt;androidx.constraintlayout.widget.ConstraintLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:background="@color/colorPrimary" android:id="@+id/constraintLayout"&gt;
  
                      &lt;TextView
                          android:text="Give £8, Get £8"
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:textColor="@color/white"
                          android:textSize="@dimen/field_header_title_text"
                          android:fontFamily="@font/apercu_medium"
                          android:id="@+id/textView2" android:layout_marginTop="8dp"
                          android:layout_marginStart="16dp"
                          app:layout_constraintStart_toStartOf="parent"
                          app:layout_constraintTop_toTopOf="parent"/&gt;
                      &lt;TextView
                          android:text="Give your friends £8 with your code and get £8 for every friend that uses it!"
                          android:layout_width="0dp"
                          android:layout_height="wrap_content"
                          android:fontFamily="@font/apercu"
                          android:textSize="@dimen/discover_message_text_size"
                          android:textColor="@color/text_white"
                          android:lineSpacingExtra="10dp"
                          android:id="@+id/textView3" android:layout_marginTop="16dp"
                          app:layout_constraintTop_toBottomOf="@+id/textView2"
                          app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent"
                          android:layout_marginEnd="32dp" android:layout_marginStart="16dp"/&gt;
                      &lt;LinearLayout
                          android:orientation="horizontal"
                          android:layout_width="0dp"
                          android:layout_height="80dp"
                          app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="8dp"
                          app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="8dp"
                          android:layout_marginTop="24dp" app:layout_constraintTop_toBottomOf="@+id/textView3"
                          android:id="@+id/linearLayout" android:layout_marginBottom="8dp"
                          app:layout_constraintBottom_toBottomOf="parent"&gt;
                          &lt;LinearLayout
                              android:orientation="vertical"
                              android:layout_width="0dp"
                              android:layout_weight="1"
                              android:layout_height="match_parent"
                              android:gravity="center"
                              android:layout_margin="8dp"
                              android:background="@drawable/white_radius"&gt;
                              &lt;TextView
                                  android:layout_width="match_parent"
                                  android:fontFamily="@font/apercu_bold"
                                  android:textColor="@color/warm_grey"
                                  android:layout_height="wrap_content"
                                  android:gravity="center"
                                  android:textSize="24sp"
                                  android:id="@+id/txt_pending_invites"/&gt;
                              &lt;TextView
                                  android:text="Pending invites"
                                  android:layout_width="match_parent"
                                  android:fontFamily="@font/apercu"
                                  android:lineSpacingExtra="10dp"
                                  android:textColor="@color/greyish"
                                  android:layout_height="wrap_content" android:id="@+id/textsView5"
                                  android:gravity="center"/&gt;
                          &lt;/LinearLayout&gt;
  
                          &lt;LinearLayout
                              android:orientation="vertical"
                              android:layout_width="0dp"
                              android:layout_weight="1"
                              android:gravity="center"
                              android:layout_margin="8dp"
                              android:layout_height="match_parent"
                              android:background="@drawable/white_radius"&gt;
                              &lt;TextView
                                  android:layout_width="match_parent"
                                  android:fontFamily="@font/apercu_bold"
                                  android:textColor="@color/warm_grey"
                                  android:layout_height="wrap_content"
                                  android:gravity="center"
                                  android:textSize="24sp"
                                  android:id="@+id/txt_earned"/&gt;
                              &lt;TextView
                                  android:text="Total earned to date"
                                  android:layout_width="match_parent"
                                  android:fontFamily="@font/apercu"
                                  android:lineSpacingExtra="10dp"
                                  android:textColor="@color/greyish"
                                  android:layout_height="wrap_content" android:id="@+id/textView5"
                                  android:gravity="center"/&gt;
                          &lt;/LinearLayout&gt;
  
                      &lt;/LinearLayout&gt;
  
                  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  
                  &lt;androidx.constraintlayout.widget.ConstraintLayout
                          android:layout_width="match_parent"
                          android:layout_height="100dp"
                          tools:layout_editor_absoluteX="16dp" android:layout_marginTop="8dp"
                          app:layout_constraintTop_toBottomOf="@+id/constraintLayout"
                          android:id="@+id/constraintLayout3"&gt;
  
                      &lt;androidx.constraintlayout.widget.ConstraintLayout
                              android:layout_width="0dp"
                              android:background="@drawable/edittextround"
                              android:layout_height="50dp" app:layout_constraintBottom_toBottomOf="parent"
                              android:layout_marginBottom="8dp" app:layout_constraintStart_toStartOf="parent"
                              android:layout_marginTop="8dp" app:layout_constraintTop_toTopOf="parent"
                              app:layout_constraintEnd_toEndOf="parent" android:layout_marginStart="15dp"
                              android:layout_marginEnd="15dp" android:id="@+id/constraintLayout2"&gt;
                          &lt;TextView
                              android:id="@+id/txt_promo_code"
                              android:layout_width="0dp"
                              android:layout_height="wrap_content"
                              android:maxLines="1"
                              android:textSize="16sp"
                              android:text=""
                              android:textColor="@color/evergreen"
                              android:background="@android:color/transparent" android:layout_marginBottom="8dp"
                              app:layout_constraintBottom_toBottomOf="parent" android:layout_marginTop="8dp"
                              app:layout_constraintTop_toTopOf="parent"
                              app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="20dp"
                              app:layout_constraintEnd_toStartOf="@+id/invite_button"/&gt;
                          &lt;Button
                              android:text="Share"
                              android:layout_width="wrap_content"
                              android:background="@drawable/form_button_radius"
                              android:textAppearance="@style/BottomButtonAppearance"
                              android:layout_height="32dp"
                              android:id="@+id/invite_button"
                              app:layout_constraintEnd_toEndOf="parent"
                              android:layout_marginEnd="8dp" android:layout_marginBottom="0dp"
                              app:layout_constraintBottom_toBottomOf="parent" android:layout_marginTop="0dp"
                              app:layout_constraintTop_toTopOf="parent"/&gt;
  
                      &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  
                      &lt;TextView
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:background="?android:colorBackground"
                          android:includeFontPadding="false"
                          android:paddingLeft="5dp"
                          android:paddingRight="5dp"
                          android:textSize="13sp"
                          android:text="Share Code"
                          android:textColor="@color/warm_grey"
                          android:fontFamily="@font/apercu"
                          android:textAppearance="@android:style/TextAppearance.Medium"
                          app:layout_constraintEnd_toEndOf="@+id/constraintLayout2"
                          app:layout_constraintStart_toStartOf="@+id/constraintLayout2"
                          app:layout_constraintHorizontal_bias="0.05" android:layout_marginTop="8dp"
                          app:layout_constraintTop_toTopOf="@+id/constraintLayout2"
                          app:layout_constraintBottom_toTopOf="@+id/constraintLayout2"/&gt;
  
                  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  
                  &lt;TextView
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:textSize="18sp"
                      android:textColor="@color/black"
                      android:letterSpacing="-0.01"
                      android:lineSpacingExtra="4sp"
                      android:text="Invite your contacts"
                      app:layout_constraintTop_toBottomOf="@+id/constraintLayout3"
                      android:layout_marginStart="16dp" app:layout_constraintStart_toStartOf="parent"
                      android:id="@+id/textView" android:layout_marginTop="12dp"/&gt;
  
                  &lt;TextView
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:textSize="16sp"
                      android:textColor="@color/warm_grey"
                      android:lineSpacingExtra="10sp"
                      android:visibility="gone"
                      android:text="Send your friends and family a link and you both get rewarded when they sign up."
                      android:layout_marginTop="12dp"
                      app:layout_constraintTop_toBottomOf="@+id/textView" android:id="@+id/txt_invite"
                      android:layout_marginStart="16dp" app:layout_constraintStart_toStartOf="parent"/&gt;
  
                  &lt;androidx.constraintlayout.widget.ConstraintLayout
                      android:layout_width="match_parent"
                      android:layout_height="220dp"
                      android:background="@drawable/white_radius"
                      app:layout_constraintTop_toBottomOf="@+id/txt_invite"
                      app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="16dp"
                      app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="16dp"
                      android:id="@+id/permission_layout"&gt;
                      &lt;Button
                          android:text="Give Access"
                          android:layout_width="0dp"
                          android:background="@drawable/form_button_radius"
                          android:textAppearance="@style/BottomButtonAppearance"
                          android:layout_height="48dp"
                          android:id="@+id/btn_give_access"
                          app:layout_constraintEnd_toEndOf="parent"
                          android:layout_marginEnd="16dp"
                          android:layout_marginStart="16dp"
                          app:layout_constraintStart_toStartOf="parent"
                          app:layout_constraintTop_toBottomOf="@+id/textView6" android:layout_marginTop="16dp"/&gt;
                      &lt;TextView
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:textSize="13sp"
                          android:textColor="@color/warm_grey"
                          android:lineSpacingExtra="7sp"
                          android:gravity="center_horizontal"
                          android:text="@string/to_send_your_friends_and_family_a_referral_link_please_give_us_access_to_your_contacts"
                          tools:layout_editor_absoluteX="0dp"
                          android:layout_marginTop="16dp" app:layout_constraintTop_toBottomOf="@+id/imageView2"
                          android:id="@+id/textView6"/&gt;
                      &lt;ImageView
                          android:layout_width="60dp"
                          android:layout_height="60dp" app:srcCompat="@drawable/icon_person"
                          android:id="@+id/imageView2" android:layout_marginTop="20dp"
                          app:layout_constraintTop_toTopOf="parent" app:layout_constraintEnd_toEndOf="parent"
                          android:layout_marginEnd="8dp" app:layout_constraintStart_toStartOf="parent"
                          android:layout_marginStart="8dp"/&gt;
                  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  
  
                  &lt;androidx.recyclerview.widget.RecyclerView
                      android:id="@+id/contact_recycler"
                      android:layout_width="match_parent"
                      android:layout_height="match_parent"
                      tools:listitem="@layout/item_contact"
                      tools:layout_editor_absoluteX="0dp" android:layout_marginTop="16dp"
                      app:layout_constraintTop_toBottomOf="@+id/permission_layout"/&gt;
  
                  &lt;ProgressBar android:layout_width="wrap_content" android:layout_height="wrap_content"
                      app:layout_constraintTop_toBottomOf="@+id/permission_layout"
                      android:indeterminate="true"
                      android:indeterminateTintMode="src_atop"
                      android:indeterminateTint="@color/colorPrimary"
                      android:visibility="gone"
                      app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="8dp"
                      app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="17dp"
                      android:progressTint="@color/warm_grey" android:layout_marginTop="24dp"
                      android:id="@+id/progress_bar"/&gt;
  
              &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  
          &lt;/androidx.core.widget.NestedScrollView&gt;
  
      &lt;/LinearLayout&gt;
  &lt;layout&gt;
  </code></pre>
  
  <p><strong>Code for adapter</strong></p>
  
  <pre><code>internal class ContactAdapter(context: Context, private val mProductList:   ArrayList&lt;ContactModel&gt;) : RecyclerView.Adapter&lt;ContactAdapter.MyViewHolder&gt;() {
      private val inflater: LayoutInflater;
      private val key: String? = null;
  
      init {
          inflater = LayoutInflater.from(context);
      }
  
      override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
          val view = inflater.inflate(R.layout.item_contact, parent, false);
          return MyViewHolder(view);
      }
  
      override fun onBindViewHolder(holder: MyViewHolder, position: Int){
          val selectedProduct = mProductList[position];
          holder.setData(selectedProduct);
  
      }
  
      override fun getItemCount(): Int {
          return mProductList.size;
      }
  
      internal inner class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), View.OnClickListener {
          fun setData(selectedProduct: ContactModel)
          {
              itemView.txt_name.text = selectedProduct.name;
              itemView.txt_number.text = selectedProduct.number;
          }
  
          override fun onClick(v: View)
          {
  
          }
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/TELtO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TELtO.png" alt="screenshot for screen"></a></p>