Java Don';我不明白如何使用GridLayout.spec()

Java Don';我不明白如何使用GridLayout.spec(),java,android,grid-layout,specifications,Java,Android,Grid Layout,Specifications,这个GridLayout在我的应用程序中有很多级别。每个级别都有不同数量的行和列。我认为这个GridLayout将是我满足需求的最佳选择。此外,所有这些都需要在运行时按程序完成 我无法理解如何使用GridLayout.spec()。我试图跟随,但就是不能完全掌握它。比如说,我想要一个3列4行的GridLayout GridLayout.LayoutParms params1 = new GridLayout.Layout(rowSpec, columnSpec); //what's param

这个GridLayout在我的应用程序中有很多级别。每个级别都有不同数量的行和列。我认为这个GridLayout将是我满足需求的最佳选择。此外,所有这些都需要在运行时按程序完成

我无法理解如何使用
GridLayout.spec()
。我试图跟随,但就是不能完全掌握它。比如说,我想要一个3列4行的GridLayout

GridLayout.LayoutParms params1 = new GridLayout.Layout(rowSpec, columnSpec);  //what's parameters?

gameplayGridLayout.setColumnCount(3);
gameplayGridLayout.setRowCount(4);

puzzle.addView(gameplayGridLayout, params1);
在我上面的链接示例中,他使用如下代码设置
“specs”


我也不明白这些变量的参数。我试着阅读文档,但没有给我任何清晰的印象。有人能帮我解释一下3x4 GridLayout的示例代码吗?这也有助于解释
Spec
s是什么?

我并不完全理解你的问题,但下面是一些解释语法的示例:

Spec row1 = GridLayout.spec(0, 2); //here you set row to be first row and it takes 2 cells in height.

Spec row2  = GridLayout.spec(2); //this row goes under row1 and it takes 1 cell(default size = 1) 
等等

Spec col0 = GridLayout.spec(0); //same here - first column, width = 1 cell.

Spec colspan2 = GridLayout.spec(0, 2);
所以你可以这样做:

Spec row1 = GridLayout.spec(0);
Spec row2 = GridLayout.spec(1);
Spec row3 = GridLayout.spec(2);
Spec row4 = GridLayout.spec(3);

Spec col0 = GridLayout.spec(0);
Spec col1 = GridLayout.spec(1); 
Spec col2 = GridLayout.spec(2);

GridLayout gridLayout = new GridLayout(this);
GridLayout.LayoutParams first = new GridLayout.LayoutParams(row1, col0);
/*Here you can set options for first cell which is in first row and first column.*/
first.width = screenWidth;
first.height = quarterScreenWidth * 2;
twoByTwo1.setLayoutParams(first);
twoByTwo1.setGravity(Gravity.CENTER);
twoByTwo1.setBackgroundColor(Color.RED);
twoByTwo1.setText("TOP");
twoByTwo1.setTextAppearance(this, android.R.style.TextAppearance_Large);
gridLayout.addView(twoByTwo1, first)
//You can set all cells like above.
我希望这有帮助。:)

Spec row1 = GridLayout.spec(0);
Spec row2 = GridLayout.spec(1);
Spec row3 = GridLayout.spec(2);
Spec row4 = GridLayout.spec(3);

Spec col0 = GridLayout.spec(0);
Spec col1 = GridLayout.spec(1); 
Spec col2 = GridLayout.spec(2);

GridLayout gridLayout = new GridLayout(this);
GridLayout.LayoutParams first = new GridLayout.LayoutParams(row1, col0);
/*Here you can set options for first cell which is in first row and first column.*/
first.width = screenWidth;
first.height = quarterScreenWidth * 2;
twoByTwo1.setLayoutParams(first);
twoByTwo1.setGravity(Gravity.CENTER);
twoByTwo1.setBackgroundColor(Color.RED);
twoByTwo1.setText("TOP");
twoByTwo1.setTextAppearance(this, android.R.style.TextAppearance_Large);
gridLayout.addView(twoByTwo1, first)
//You can set all cells like above.