blessanm86
blessanm86

Reputation: 31779

Creating 3*3 grid using the new GridLayout

Is it possible to create a 3*3 grid using the new GridLayout in ICS. I tried many methods like specifying the rowCount and columnCount to 3. I just cant figure out the basics of gridlayout.

I want to create a grid where layout splits the available space into equal sized cells.

I was able to create an icon grid but the size was not equal. Each cell took the size of the icon.

I am not looking into alternate layouts as I am trying to figure out how the GridLayout is used.

Upvotes: 2

Views: 2197

Answers (2)

Shanmukh
Shanmukh

Reputation: 1

Below code worked for me

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_columnSpan="1"
android:layout_gravity="fill"
android:layout_rowSpan="1"

Upvotes: 0

Alexander Lucas
Alexander Lucas

Reputation: 22371

That's really more TableLayout's bag. GridLayout is meant to help flatten what can otherwise become deeply nested view hierarchies. This blog post gives a great overview of what it's good at and why it's there. Notice how in diagrams, GridLayout's grid is snapping to the sizes of the various views inside of it.

If you absolutely wanted to use GridLayout instead of TableLayout to accomplish the layout you're describing anyway, one (slightly hackish) solution would be to just create 9 copies of a fixed view, set them to (available width / 3) x (available height / 3), and add them as children to the GridLayout. But, one more time, this isn't the case GridLayout is for.

Upvotes: 1

Related Questions