1

I am currently learning the Android front-end development, and our teacher gave us this task:

We need to create the next grid in Android Studio: Task Grid using GridLayout. For now I only created this.

Is there way to display the last two blocks of the GridLayout in full width?

Cactusroot
  • 1,019
  • 3
  • 16

2 Answers2

0

I am not sure if it works, but this post does not recommend it.

You could just put a LinearLayout with android:orientation="vertical" and android:width="match_parent" or another GridLayout below your GridLayout.

If you don't have any wrapping layout, wrap both of them into a LinearLayout with android:orientation="vertical" and put all the properties of your original GridLayout there.

Cactusroot
  • 1,019
  • 3
  • 16
0

Have a look at SpanSizeLookup.

Something like:

val layoutManager = GridLayoutManager(activity, 2)
layoutManager.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
    override fun getSpanSize(position: Int): Int {
        return when (position) {
            YOUR_CONDITION -> 2
            else -> 1
        }
   }
}
recyclerView.layoutManager = layoutManager

Replace YOUR_CONDITION with some logic fits your requirements to make a cell twice higher.

Vasily Kabunov
  • 6,511
  • 13
  • 49
  • 53