title: How to make RecyclerView's grid item to have equal height and width?
body: <p>I define my <code>RecyclerView</code> as grid by setting its layout with <code>GridLayoutManger</code> that has a span count of 3 which are already working fine. I also add an item decorator to my recycler view which will manage the spacing between grid items, this also works fine.</p>
  
  <pre><code>public class GridSpacingItemDecoration extends RecyclerView.ItemDecoration {
  
      private int spanCount;
      private int spacing;
      private boolean includeEdge;
  
      public GridSpacingItemDecoration(int spanCount, int spacing, boolean includeEdge) {
          this.spanCount = spanCount;
          this.spacing = spacing;
          this.includeEdge = includeEdge;
      }
  
      @Override
      public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
          int position = parent.getChildAdapterPosition(view); // item position
          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
              }
          }
      }
  }
  </code></pre>
  
  <p>My implementation for adding item decoration to my Recycler View:</p>
  
  <pre><code>mBuddiesGrid = (RecyclerView) findViewById(R.id.buddies_grid);
          mLayoutManager = new GridLayoutManager(getApplicationContext(), 3);
          mBuddiesGrid.addItemDecoration(new GridSpacingItemDecoration(3, (int) dpToPx(10) , true));
          mBuddiesAdapter = new BuddiesGridAdapter(getApplicationContext(), new Buddies());
          mBuddiesGrid.setLayoutManager(mLayoutManager);
  </code></pre>
  
  <p>My grid item xml layout :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      xmlns:android="http://schemas.android.com/apk/res/android"&gt;
  
      &lt;ImageView
          android:layout_weight="1"
          android:cropToPadding="false"
          android:id="@+id/profile_picture"
          android:scaleType="centerCrop"
          android:layout_width="match_parent"
          android:layout_height="match_parent" /&gt;
  
      &lt;TextView
          android:text="Theodore"
          android:includeFontPadding="false"
          android:textColor="@android:color/black"
          android:id="@+id/name"
          android:layout_width="match_parent"
          android:layout_height="wrap_content" /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>By adding spaces between grid item will adjust the grid item's width which can possibly cause of not getting the proportion size of my item view. What I want to obtain is to resize my grid item height equal to its width dynamically. How can I do it?</p>