【发布时间】:2014-02-25 08:18:07
【问题描述】:
我已阅读文档,查看了一些示例代码。我仍然不明白如何正确使用 GridLayouts。我特别怀疑我不了解 Android 规范。
我现在想做的就是在 GridLayout 的 1 行中放置 2 个按钮。我该怎么做?
这就是我所拥有的:首先我创建规范。//6 rows is the goal of this ViewSpec rowSpec1 = GridLayout.InvokeSpec(0, 5, GridLayout.Center);Spec colSpec1 = GridLayout.InvokeSpec(0);Spec colSpec1 = GridLayout.InvokeSpec(0)
创建要添加的按钮:Button bt1 = new Button(this._Context);
Button bt2 = new Button(this._Context);
//the this keyword is just referring to my class that extends GridLayout
//Where I've stored the Activity's Context
现在让我们将按钮添加到网格中:this.AddView(bt1, new GridLayout.LayoutParams(rowSpec1, colSpec1));
this.AddView(bt2, new GridLayout.LayoutParams(rowSpec1, colSpec2));
这样做的结果是我的 Android 设备左上角的一个按钮。如何以编程方式将这些按钮插入所需的位置?另外,我读过 Specs 实际上只是用于对齐目的,但我看到的代码看起来像是用于子视图的行和列放置;这就是我正在做的。有人可以以一种愚蠢的方式为我解释 Android 规格吗?谢谢大家!
【问题讨论】:
标签: android xamarin android-gridlayout