【发布时间】:2011-08-25 22:10:33
【问题描述】:
我遇到了 2 个动态创建的布局的问题,外面的一个是 LinearLayout,它包含一个 relativeLayout 和一个 Button(只是为了测试,我很快就会有更多的按钮)。
我的相对布局基本上是数独游戏的 9x9 按钮排列。
我现在的问题如下,我希望将 relativeLayout 放在 Button 的顶部,而不是在它的下方。以下代码将其放在下面:
MainLayout lay = new MainLayout(this); // MainLayout is derived from RelativeLayout
LinearLayout outerLay = new LinearLayout(this);
outerLay.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
outerLay.setOrientation(LinearLayout.VERTICAL);
Button but = new Button(this);
outerLay.addView(but);
outerLay.addView(lay);
setContentView(outerLay);
这很好用,但如果我像这样重新排列它们:
outerLay.addView(lay);
outerLay.addView(but);
按钮甚至不显示。有人对此有任何线索吗? (顺便说一句,垂直方向也是如此。)。
您好。
【问题讨论】:
标签: android android-linearlayout android-relativelayout