skip to Main Content

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?

2

Answers


  1. 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.

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search