title: Recyclerview Grid layout item cut issue
body: <p>I want to display list in recyclerView with grid layout with 2 columns. But when i apply item decor class then item is cutting from right side. Please checl below screenshot and code for the same. Do let me know if anyone have any idea on this.</p>
  <p><a href="https://i.stack.imgur.com/9y6nJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9y6nJ.png" alt="enter image description here" /></a></p>
  <p><strong>Row file xml :</strong></p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;layout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;&gt;
  
      &lt;data&gt;
  
          &lt;variable
              name=&quot;viewModel&quot;
              type=&quot;com.sg.gbb.ui.tourplantcollection.viewmodel.PlantCollectionAdapterViewModel&quot; /&gt;
      &lt;/data&gt;
  
      &lt;LinearLayout
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;&gt;
  
          &lt;androidx.cardview.widget.CardView
              android:layout_width=&quot;164dp&quot;
              android:layout_height=&quot;wrap_content&quot;
              app:cardCornerRadius=&quot;8dp&quot;
              app:cardElevation=&quot;0dp&quot;&gt;
  
              &lt;LinearLayout
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:background=&quot;@color/screen_bg&quot;
                  android:orientation=&quot;vertical&quot;&gt;
  
                  &lt;ImageView
                      android:layout_width=&quot;match_parent&quot;
                      android:layout_height=&quot;164dp&quot;
                      android:contentDescription=&quot;@string/gbb_app_name&quot;
                      android:scaleType=&quot;fitXY&quot;
                      android:src=&quot;@color/flower_bg&quot; /&gt;
  
                  &lt;com.sg.gbb.ui.custom.GBBTextView
                      android:id=&quot;@+id/tvOrderOn&quot;
                      android:layout_width=&quot;match_parent&quot;
                      android:layout_height=&quot;match_parent&quot;
                      android:layout_gravity=&quot;center_vertical&quot;
                      android:layout_marginStart=&quot;16dp&quot;
                      android:layout_marginTop=&quot;11dp&quot;
                      android:layout_marginEnd=&quot;16dp&quot;
                      android:layout_marginBottom=&quot;16dp&quot;
                      android:gravity=&quot;center&quot;
                      android:text=&quot;@{viewModel.code}&quot;
                      android:textColor=&quot;@color/greyishBrown&quot;
                      android:textSize=&quot;15sp&quot;
                      app:customFont=&quot;@string/gardens_light&quot; /&gt;
  
              &lt;/LinearLayout&gt;
  
          &lt;/androidx.cardview.widget.CardView&gt;
  
      &lt;/LinearLayout&gt;
  
  &lt;/layout&gt;
  </code></pre>
  <p><strong>My recyclerView file :</strong></p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;layout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;&gt;
  
      &lt;data&gt;
  
          &lt;variable
              name=&quot;viewModel&quot;
              type=&quot;com.sg.gbb.ui.tourplantcollection.viewmodel.PlantCollectionViewModel&quot; /&gt;
      &lt;/data&gt;
  
      &lt;RelativeLayout
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;match_parent&quot;
          android:background=&quot;@color/white&quot;
          android:gravity=&quot;center_horizontal&quot;
          android:orientation=&quot;vertical&quot;&gt;
  
          &lt;ImageView
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;150dp&quot;
              android:background=&quot;@color/black_80_opacity&quot;
              android:contentDescription=&quot;@string/gbb_app_name&quot; /&gt;
  
          &lt;LinearLayout
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:layout_marginTop=&quot;100dp&quot;
              android:background=&quot;@drawable/bg_edit_profile&quot;
              android:orientation=&quot;vertical&quot;&gt;
  
              &lt;LinearLayout
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;0dp&quot;
                  android:layout_weight=&quot;1&quot;
                  android:orientation=&quot;vertical&quot;&gt;
  
                  &lt;com.sg.gbb.ui.custom.GBBTextView
                      android:id=&quot;@+id/titleTextview&quot;
                      android:layout_width=&quot;wrap_content&quot;
                      android:layout_height=&quot;wrap_content&quot;
                      android:layout_marginStart=&quot;16dp&quot;
                      android:layout_marginTop=&quot;20dp&quot;
                      android:layout_marginBottom=&quot;20dp&quot;
                      android:text=&quot;@string/plant_collection_text&quot;
                      android:textColor=&quot;@color/greyishBrown&quot;
                      android:textSize=&quot;15sp&quot;
                      app:customFont=&quot;@string/gardens_bold&quot; /&gt;
  
                  &lt;androidx.recyclerview.widget.RecyclerView
                      android:id=&quot;@+id/plantCollectionRV&quot;
                      android:layout_width=&quot;match_parent&quot;
                      android:layout_height=&quot;match_parent&quot;
                      android:overScrollMode=&quot;never&quot;
                      android:gravity=&quot;center&quot;
                      android:scrollbars=&quot;none&quot;
                      app:adapter=&quot;@{viewModel.plantList}&quot;
                      app:layoutManager=&quot;androidx.recyclerview.widget.GridLayoutManager&quot;
                      app:spanCount=&quot;2&quot;
                      tools:listitem=&quot;@layout/item_plant_collection&quot; /&gt;
  
              &lt;/LinearLayout&gt;
  
              &lt;View
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;1dp&quot;
                  android:background=&quot;@color/divider&quot; /&gt;
  
              &lt;com.sg.gbb.ui.custom.GBBButton
                  android:id=&quot;@+id/cancelButton&quot;
                  style=&quot;?android:attr/borderlessButtonStyle&quot;
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:layout_marginStart=&quot;16dp&quot;
                  android:layout_marginTop=&quot;26dp&quot;
                  android:layout_marginEnd=&quot;16dp&quot;
                  android:layout_marginBottom=&quot;16dp&quot;
                  android:background=&quot;@drawable/bg_dismiss_button&quot;
                  android:onClick=&quot;@{() -&gt; viewModel.onBackClicked()}&quot;
                  android:paddingStart=&quot;16dp&quot;
                  android:paddingTop=&quot;12dp&quot;
                  android:paddingEnd=&quot;16dp&quot;
                  android:paddingBottom=&quot;12dp&quot;
                  android:text=&quot;@string/back&quot;
                  android:textAllCaps=&quot;true&quot;
                  android:textColor=&quot;@color/done_text&quot;
                  android:textSize=&quot;@dimen/_12ssp&quot;
                  app:buttonFont=&quot;@string/gardens_bold&quot; /&gt;
  
          &lt;/LinearLayout&gt;
  
      &lt;/RelativeLayout&gt;
  
  &lt;/layout&gt;
  </code></pre>
  <p>Item decor file :</p>
  <pre><code>import android.graphics.Rect;
  import android.view.View;
  
  import androidx.recyclerview.widget.RecyclerView;
  
  /**
   * Created by Android Studio
   * User: Ailurus(ailurus@foxmail.com)
   * Date: 2015-10-28
   * Time: 15:20
   */
  public class EqualSpacingItemDecoration extends RecyclerView.ItemDecoration {
  
      private int spanCount;
      private int spacing;
      private boolean includeEdge;
      private int headerNum;
  
      public EqualSpacingItemDecoration(int spanCount, int spacing, boolean includeEdge, int headerNum) {
          this.spanCount = spanCount;
          this.spacing = spacing;
          this.includeEdge = includeEdge;
          this.headerNum = headerNum;
      }
  
      @Override
      public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
          int position = parent.getChildAdapterPosition(view) - headerNum; // item position
  
          if (position &gt;= 0) {
              int column = position % spanCount; // item column
  
              if (includeEdge) {
                  outRect.left = spacing - column * spacing / spanCount; // spacing - column * ((1f / spanCount) * spacing)
                  outRect.right = (column + 1) * spacing / spanCount; // (column + 1) * ((1f / spanCount) * spacing)
  
                  if (position &lt; spanCount) { // top edge
                      outRect.top = spacing;
                  }
                  outRect.bottom = spacing; // item bottom
              } else {
                  outRect.left = column * spacing / spanCount; // column * ((1f / spanCount) * spacing)
                  outRect.right = spacing - (column + 1) * spacing / spanCount; // spacing - (column + 1) * ((1f /    spanCount) * spacing)
                  if (position &gt;= spanCount) {
                      outRect.top = spacing; // item top
                  }
              }
          } else {
              outRect.left = 0;
              outRect.right = 0;
              outRect.top = 0;
              outRect.bottom = 0;
          }
      }
  }
  </code></pre>