添加子视图RelativeLayout的编程

添加子视图RelativeLayout的编程

本文介绍了添加子视图RelativeLayout的编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有遍历一个列表,并返回行元素的函数。

I have a function that loops over a list and returns the row elements.

我想这些行添加到空 RelativeLayout的一个接一个,这样所有的行顺序垂直显示。

I want to add these rows to an empty RelativeLayout one by one, so that all the rows are displayed sequentially vertically.

但低于code是行不通的。

But the code below is not working.

void setRows(RelativeLayout rowContainer, ViewHolder viewHolder,
    List<RowCollection> rowCollection) {

    for (int i = 0; i < rowCollection.size(); i++) {
        MyRow row = new MyRow(rowCollection.get(i));
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, row.getId());
        rowContainer.addView(row, params);
    }
}

只显示最后一排的元素。

Only the last row element is displayed.

我想,但我不能确定,各行相互重叠的。

I guess but am not sure, that the rows are overlapping each other.

推荐答案

您正在把所有的欣赏到的RelativeLayout的底部,所以他们总是在另一个的上面。所以永远只有最后一个可见的,因为其他的都搞砸了。
更改code这样:

You are placing all your Views to the Bottom of the RelativeLayout, so they are always on top of the other. So there is always only the last one visible because the other ones are blow it.Change your Code to this:

 params.addRule(RelativeLayout.BELOW, iDFromPreviousView);

这篇关于添加子视图RelativeLayout的编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 09:47