【发布时间】:2014-08-02 07:16:15
【问题描述】:
我是 android 开发新手,我想以编程方式将 LinearLayout 视图添加到父 LinearLayout。在这样做的同时,我想按顺序查看它们。也就是说,首先添加的视图应该是 first ,其次添加的视图应该是 second ,依此类推。 我试着用
HolderLayout.addView(view, index)
索引在哪里增加,但它对我不起作用。我首先添加的视图在列表中显示在第二位。我该怎么办? 我的代码大纲是:
int index = 0;
View Row1 = View.inflate(this, R.layout.childView, null);
//populate the appropriate data on the child Row and add it to the holder layout.
holder_layout.addView(Row1 , index);
index++;
Set<Integer>keys = MyMap.keySet();
for(int i : keys){
View row = View.inflate(this,
R.layout.childView, null);
holder_layout.addView(row , index);
index++;
}
我哪里错了。
【问题讨论】:
-
定义不工作。什么不工作?到底发生了什么?
-
我在 for 循环之外添加的行是我得到的最后一项,实际上它应该是第一个?正确的?因为我在 index = 0 处添加它?
-
如果您使用垂直方向的线性布局,它将自动按顺序添加新视图
-
是的,线性布局是垂直的,不是按顺序添加的!
-
标签: android android-linearlayout