title: RecyclerView Item Size changing while scrolling
body: <p>When first time <code>recyclerView</code> Load It will show all proper. but after scrolling, layout item size changed.</p>
  <p><img src="https://i.stack.imgur.com/jZYtJ.png" alt="enter image description here" /></p>
  <p>this is my <code>item_layout</code></p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;androidx.constraintlayout.widget.ConstraintLayout
      xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;wrap_content&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:background=&quot;@drawable/item_border&quot;
      android:layout_margin=&quot;@dimen/item_margin_2&quot;&gt;
      &lt;ImageView
          android:id=&quot;@+id/imageProduct&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:contentDescription=&quot;@string/app_name&quot;
          android:scaleType=&quot;centerInside&quot;
          android:src=&quot;@drawable/ic_launcher_foreground&quot;
          app:layout_constraintTop_toTopOf=&quot;parent&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
           /&gt;
  
      &lt;TextView
          android:id=&quot;@+id/textProductTitle&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:textColor=&quot;@android:color/black&quot;
          android:textSize=&quot;@dimen/title_textSize&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toBottomOf=&quot;@id/imageProduct&quot;
          tools:text=&quot;TubeLight&quot; /&gt;
  
      &lt;TextView
          android:id=&quot;@+id/textProductDetailSort&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_marginTop=&quot;4dp&quot;
          android:textColor=&quot;@android:color/black&quot;
          android:textSize=&quot;@dimen/detail_textSize&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toBottomOf=&quot;@id/textProductTitle&quot;
          tools:text=&quot;warranty: 100 days&quot; /&gt;
  
  
      &lt;LinearLayout
          android:id=&quot;@+id/linerCartItem&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:orientation=&quot;horizontal&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toBottomOf=&quot;@id/textProductDetailSort&quot;&gt;
  
          &lt;ImageButton
              android:id=&quot;@+id/buttonRemove&quot;
              android:layout_width=&quot;wrap_content&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:background=&quot;@drawable/item_border_small&quot;
              android:src=&quot;@drawable/ic_outline_remove_24&quot;/&gt;
  
          &lt;TextView
              android:id=&quot;@+id/textNumberItem&quot;
              android:layout_width=&quot;wrap_content&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:background=&quot;@color/colorPrimaryLight&quot;
              android:textSize=&quot;@dimen/detail_small_textSize&quot;
              android:padding=&quot;@dimen/item_padding&quot;
              android:textColor=&quot;@color/black&quot;
              android:layout_margin=&quot;@dimen/item_margin_3&quot;
              android:text=&quot;0&quot;/&gt;
  
          &lt;ImageButton
              android:id=&quot;@+id/buttonAdd&quot;
              android:layout_width=&quot;wrap_content&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:background=&quot;@drawable/item_border_small&quot;
              android:src=&quot;@drawable/ic_baseline_add_24&quot;/&gt;
  
      &lt;/LinearLayout&gt;
  
  
      &lt;TextView
          android:id=&quot;@+id/textViewProductPrice&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toBottomOf=&quot;@id/linerCartItem&quot;
          app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
          android:layout_marginStart=&quot;@dimen/item_margin&quot;
          android:text=&quot;@string/title_price&quot;/&gt;
  
  
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  </code></pre>
  <p>this is <code>adapter class</code></p>
  <pre><code>class ProductListAdapter(context: Context, private val cellClickListener: HomeFragment) : RecyclerView.Adapter&lt;RecyclerView.ViewHolder&gt;() {
  
      interface CellClickListener {
          fun onCellClickListener(productModel: ProductModel)
          fun onNextClicked()
          fun onPrevClicked()
          fun onAddClicked(productId: String): Int
          fun onRemoveClicked(productId: String): Int
      }
  
      val FOOTER_TYPE : Int = 1
      val HEADER_TYPE : Int = 2
      var context : Context = context
  
      private var listOfProducts = listOf&lt;ProductModel&gt;()
  
  
      override fun getItemViewType(position: Int): Int {
  
           if (position ==  listOfProducts.size) {
  
               return FOOTER_TYPE
           }
  //         else if(position == 0){
  //            return HEADER_TYPE
  //         }
          return 0
  
      }
      override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
  
          if (viewType == FOOTER_TYPE){
              return ProductListViewHolderFooter(
                  LayoutInflater.from(parent.context).inflate(
                      R.layout.item_product_footer,
                      parent, false
                  )
              )
          }else if(viewType == HEADER_TYPE){
              return ProductListViewHolderHeader(
                  LayoutInflater.from(parent.context).inflate(
                      R.layout.item_product_header,
                      parent, false
                  )
              )
          }
          else{
              return ProductListViewHolder(
                  context,
                  LayoutInflater.from(parent.context).inflate(
                      R.layout.item_product,
                      parent,
                      false
                  )
              )
          }
  
      }
  
      override fun getItemCount(): Int = listOfProducts.size + 1
  
      override fun onBindViewHolder(viewHolder: RecyclerView.ViewHolder, position: Int) {
          try {
              if (viewHolder is ProductListViewHolder) {
                  val vh: ProductListViewHolder = viewHolder as ProductListViewHolder
                  vh.bindView(listOfProducts[position], cellClickListener)
  
              } else if (viewHolder is ProductListViewHolderFooter) {
                  val vh: ProductListViewHolderFooter = viewHolder as ProductListViewHolderFooter
                  vh.bindViewFooter(listOfProducts[position], cellClickListener)
              }
          } catch (e: Exception) {
              e.printStackTrace()
          }
  
  
      }
  
      fun setProductList(listOfProducts: List&lt;ProductModel&gt;) {
  
          this.listOfProducts = listOfProducts
          notifyDataSetChanged()
      }
  }
  </code></pre>
  <p>and this is <code>holder</code></p>
  <pre><code>class ProductListViewHolder(context: Context,itemView: View) : RecyclerView.ViewHolder(itemView){
  
     
      var sharedPreferences: SharedPreferences = context.getSharedPreferences(utils.PREFERENCE_FILE_NAME,
          Context.MODE_PRIVATE)
    
  
      fun bindView(productModel: ProductModel, cellClickListener: HomeFragment) {
          itemView.textProductTitle.text = productModel.productTitle
          itemView.textProductDetailSort.text = productModel.productDetailSort
  
  
          itemView.textViewProductPrice.text = context.getString(R.string.title_price) + &quot;: &quot; + productModel.price
  
         
          itemView.textNumberItem.text = cart
  
          Glide.with(itemView.context).load(productModel.productImageUrl!!).into(itemView.imageProduct)
  
           itemView.imageProduct.setOnClickListener{
               cellClickListener.onCellClickListener(productModel)
           }
  
           itemView.buttonRemove.setOnClickListener {
               val cart = cellClickListener.onRemoveClicked(productModel.productId)
               itemView.textNumberItem.text = cart.toString()
           }
  
           itemView.buttonAdd.setOnClickListener {
               val cart = cellClickListener.onAddClicked(productModel.productId)
               itemView.textNumberItem.text = cart.toString()
           }
  
      }
  
  
  }
  </code></pre>