0

How can I set the android:layout_column="1" programatically? I've seen some other answers but all of them are something that doesn't really work with my code. All of them say to do something like this:

layout.setLayoutParams(new TableRow.LayoutParams(columnNum)) which isn't really what I want, because I have a GridLayout and I already have a set LayoutParams.

My LayoutParams go like this:

GridLayout.LayoutParams middleLayoutLayoutParams = (GridLayout.LayoutParams)middleLayout.getLayoutParams();
middleLayoutLayoutParams.columnSpec = col2;
middleLayout.setLayoutParams(middleLayoutLayoutParams);
numBoxes++;

But I want something like: middleLayout.column = GridLayout.spec(1)?

Any way to achieve this?

Groot
  • 483
  • 1
  • 9
  • 20

1 Answers1

2

Let's assume I have a TextView textViewName in the grid. Now I place it in row 1, column 1 with a column span of 4.

    lpGl = new GridLayout.LayoutParams();
    lpGl.height = LayoutParams.WRAP_CONTENT;
    lpGl.width = LayoutParams.WRAP_CONTENT;
    lpGl.columnSpec = GridLayout.spec(0, 4);
    lpGl.rowSpec = GridLayout.spec(1);
    textViewName.setLayoutParams(lpGl);

Would this work for you?

user3460486
  • 508
  • 1
  • 4
  • 14
  • Thanks for replying on four of my questions! I haven't tried it just yet but I will and I'll let you know how it goes. – Groot Aug 20 '14 at 23:26