80,359
社区成员
发帖
与我相关
我的任务
分享
// 行设置,第一个为参数为第几行,默认可不设置,第二个参数为跨行数,没有则表示不跨行
Spec row1 = GridLayout.spec(GridLayout.UNDEFINED);
// 列设置,第一个为参数为第几列,默认可不设置,第二个参数为跨列数,没有则表示不跨行
Spec col0 = GridLayout.spec(GridLayout.UNDEFINED,4);
GridLayout.LayoutParams first = new GridLayout.LayoutParams(row1, col0);
first.width = GridLayout.LayoutParams.MATCH_PARENT;
first.height = GridLayout.LayoutParams.WRAP_CONTENT;
TextView twoByTwo1 = new TextView(this);
twoByTwo1.setLayoutParams(first);
twoByTwo1.setGravity(Gravity.CENTER);
twoByTwo1.setBackgroundColor(Color.RED);
twoByTwo1.setText("text");
gridLayout.addView(twoByTwo1, first);
代码如上