title: RecyclerView GridLayoutManager item decoration takes measured space?
body: <p>I am creating a vertical RecyclerView with three columns (to simplify illustration I have made the RecyclerView contain only 6 items). What I need is the items on the sides get bigger margin so I use an ItemDecoration to achieve this:</p>
  
  <pre><code>class SpaceDecoration : RecyclerView.ItemDecoration() {
  
      override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
          val position = parent.getChildAdapterPosition(view)
          outRect.left = when(position) {
              0, 3 -&gt; 160 // Left most two items
              else -&gt; 10 // others
          }
          outRect.right = when(position) {
              2, 5 -&gt; 160 // Right most two items
              else -&gt;0 // others
          }
          outRect.top = 10
          outRect.bottom = 0
      }
  }
  </code></pre>
  
  <p>What I want is the item body to have the same width. However they are not. It looks like the GridLayoutManager measures the ItemDecoration size when equally dividing the space. How can I make the items appear equal width? I certainly do not want GridLayoutManager to measure the ItemDecoration.
  <a href="https://i.stack.imgur.com/JI1S5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JI1S5.png" alt="enter image description here"></a></p>
  
  <p>Here are the remaining code:</p>
  
  <p>MainActivity.kt:</p>
  
  <pre><code>class MainActivity : AppCompatActivity() {
      private lateinit var recyclerView: RecyclerView
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_main)
          recyclerView = findViewById(R.id.grid)
          recyclerView.layoutManager = GridLayoutManager(this,3,  RecyclerView.VERTICAL, false)
          recyclerView.adapter = GridAdapter()
          recyclerView.addItemDecoration(SpaceDecoration())
      }
  }
  </code></pre>
  
  <p>GridAdapter.kt:</p>
  
  <pre><code>class GridAdapter : RecyclerView.Adapter&lt;RecyclerView.ViewHolder&gt;() {
      override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder =
          VH(LayoutInflater.from(parent.context).inflate(R.layout.grid_item, parent, false))
      override fun getItemCount() = 6
      override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) = Unit
      class VH(item: View) : RecyclerView.ViewHolder(item)
  }
  </code></pre>
  
  <p>grid_item.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;TextView
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:textSize="48sp"
      android:text="AAA"
      android:gravity="center"
      android:background="@color/colorAccent"/&gt;
  </code></pre>