如何在相对布局包含器内的其他两个视图之间添加视图?

我有孩子意见RelativeLayout容器,就像这样:被编程产生如何在相对布局包含器内的其他两个视图之间添加视图?

[ -> begin of relative layout containner 

[view] -> view (LinearLayout)

[view] -> view (LinearLayout) + rule (below of previous view)

[view] -> view (LinearLayout) + rule (below of previous view)

] -> end of relative layout

一切。

事件发生后,我需要在两个子视图之间添加一个子项。我做这个:

public void add(PerguntaViewContainner parent, PerguntaViewContainner child) { 

PerguntaViewContainner previousChild = parent;

PerguntaViewContainner nextChild = HocusPocus.getNextElementOf(parent);

perguntaParams.addRule(RelativeLayout.BELOW, previousChild.getId());

perguntaParams.addRule(RelativeLayout.ABOVE, nextChild.getId());

containner.addView(child, perguntaParams);

}

但是孩子没有出现。你有什么想法,为什么会发生?

回答:

看起来你可能需要更正其他孩子也PARAMS,如下所示:

public void add(PerguntaViewContainner parent, PerguntaViewContainner child) { 

PerguntaViewContainner previousChild = parent;

PerguntaViewContainner nextChild = HocusPocus.getNextElementOf(parent);

perguntaParams.addRule(RelativeLayout.BELOW, previousChild.getId());

perguntaParams.addRule(RelativeLayout.ABOVE, nextChild.getId());

containner.addView(child, perguntaParams);

final RelativeLayout.LayoutParams nextViewParams = (RelativeLayout.LayoutParams)nextChild.getLayoutParams();

nextViewParams.addRule(RelativeLayout.BELOW, child.getId())

nextChild.setLayoutParams(nextViewParams);

}

然而,问题是不完整的,它可以轻松地与您的自定义布局的任何问题。

以上是 如何在相对布局包含器内的其他两个视图之间添加视图? 的全部内容, 来源链接: utcz.com/qa/261922.html

回到顶部