java 中grid是什么_java – 不明白如何使用GridLayout.spec()

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

我无法理解如何使用GridLayout.spec().我试图遵循this excellent example,但却无法完全掌握它.比方说,我想要一个包含3列和4行的GridLayout.

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

gameplayGridLayout.setColumnCount(3);

gameplayGridLayout.setRowCount(4);

puzzle.addView(gameplayGridLayout, params1);

在我上面的链接示例中,他使用下面的代码来设置“规格”.

Spec row1 = GridLayout.spec(0, 2);

Spec row2 = GridLayout.spec(2);

Spec row3 = GridLayout.spec(3);

Spec row4 = GridLayout.spec(4, 2);

Spec col0 = GridLayout.spec(0);

Spec col1 = GridLayout.spec(1);

Spec colspan2 = GridLayout.spec(0, 2);

我也不了解这些变量的参数.我试过阅读文档,但它没有给我任何清晰度.有人可以帮助我使用3×4 GridLayout的示例代码,这也有助于解释规范是什么?

解决方法:

我并不完全理解您的问题,但这里有一些解释语法的示例:

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.

我希望这有帮助.

标签:grid-layout,android,java,specifications

来源: https://codeday.me/bug/20190930/1836928.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值