我有一个带有子视图的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);
}
但孩子没有露面。你知道吗,为什么会发生?
答案 0 :(得分:0)
看起来您可能还需要更正其他子参数,如下所示:
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);
}
但是,问题并不完整,您的自定义布局很容易出现问题。