0

I am trying to create a 4 x 4 GridLayout that must have 7 elements. The first 6 elements must fill 1 row and 2 columns each. The last element must be on the last row, in the middle 2 columns. The first and the last column on the last row are empty. My problem is that I can't place the last element the way I want to.

I used app:layout_gravity="fill" and I feel like I am getting a bit tangled in the layout_columnSpan and layout_columnWeight properties. I managed to place the first six elements where they belong, but I can't place the last one at the beginning of the second column. It automatically goes to the first column.

This is the code for the buttons (the first Button code is the same for all the first 6 elements, except the ID) of the GridLayout. The last one is the one that should be on the middle:

<Button
       android:background="@drawable/answer"
       android:tag="answer"
       android:layout_width="0dp"
       android:layout_height="0dp"
       app:layout_gravity="fill"
       app:layout_rowWeight="1"
       app:layout_columnWeight="2"
       app:layout_columnSpan="2"
       android:id="@+id/fAnswer" 
       android:textSize="22sp"/>

<Button
      android:background="@drawable/answer"
      android:tag="answer"
      android:layout_width="0dp"
      android:layout_height="0dp"
      app:layout_gravity="fill"
      app:layout_column="1"
      app:layout_rowWeight="1"
      app:layout_columnWeight="2"
      app:layout_columnSpan="2"
      android:id="@+id/gAnswer" 
      android:textSize="22sp"/>

Just to be clear, I expect the following result: https://i.stack.imgur.com/ffFgI.jpg

What I get is: https://i.stack.imgur.com/4LsdK.jpg

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Flendor
  • 119
  • 11
  • Why don't you use [**`FlexboxLayoutManager with RecyclerView`**](https://github.com/google/flexbox-layout#flexboxlayoutmanager-within-recyclerview) , you can find the complete answer here **[Centering RecyclerView items with FlexboxLayoutManager](https://stackoverflow.com/a/50411183/7666442)** – AskNilesh Sep 06 '19 at 13:04

1 Answers1

0

try

android:layout_span="3"
cottontail
  • 10,268
  • 18
  • 50
  • 51