I have a GridLayout with 5 columns and 3 rows. Now I can insert arbitrary child views, which is great. Even better is, that I can assign columnSpan=2 to some item in order to span it to 2 columns (the same with rowSpan).
The problem now is, that I cannot assign rowSpan or columnSpan programmatically (i.e. at runtime). Some search suggested something like this:
layoutParams.columnSpec = GridLayout.spec(0, columnSpan);
But I don’t quite understand what the parameters of spec mean (start and size). The documentation is also quite poor at this point.
Any help is highly appreciated!
OK, I spent some hours figuring out what’s going on here. Well, I didn’t find any working way to set columnSpan or rowSpan at runtime.
But I found a solution that works (at least for me):
Java code
grid_ll_col_span_2.xml
Hint: It’s very important, that you set the width and height attribute, before inflate() adds the view to the root element (i.e. the parent element).
I hope, someone can use this 😉