要将文本视图动态放置到GridLayout上,我尝试了以下代码:
GridLayout.Spec spec = new GridLayout.Spec(1,1);
GridLayout.LayoutParams params = new GridLayout.LayoutParams(spec);
产生错误:
Error:(129, 36) error: constructor Spec in class Spec cannot be applied to given types;
required: no arguments
found: int,int
reason: actual and formal argument lists differ in length
好的,我按照文档here尝试了以下代码,其中说它使用以下方法创建规范:
GridLayout.Spec spec = new GridLayout.Spec();
spec.spec(1);
但这也是不正确的。
现在我完全糊涂了。我不明白文档告诉我的是什么。也许文档过时/不正确?他们甚至没有告诉我int
值表示什么!
我希望能够为TextView
设置参数,比如列和/或放置它们的行,行的高度为文本大小......
也许某人可以展示一个简单的例子?
答案 0 :(得分:0)
以下是您应该如何使用它:
View view; // the view that you wanna insert
GridLayout.LayoutParams params =
new GridLayout.LayoutParams(view.getLayoutParams());
params.rowSpec = GridLayout.spec(0, 1); // First cell in first row uses rowSpan 1.
params.columnSpec = GridLayout.spec(0, 2); // First cell in first column uses columnSpan 2.
view.setLayoutParams(params);