Hi I just learn the Android front-end development, and our teacher gave us the task. We need to create the next grid into Android Studio: Task Grid using GridLayout. Now I think it is not possible because for now I created only this: My Result Is there way to display the last two blocks to full width into GridLayout container?
CodePudding user response:
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.
CodePudding user response:
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.