我不太了解您的问题,但以下是一些解释语法的示例:
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);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.我希望这有帮助。:)



