如何在运行时在相对布局中添加视图,以使其在父级的顶部对齐.假设我在单击按钮时添加了EditText.现在,这个EditText应该以EditText位于Button之上. 这是我正在做的一个例子. button = new Button
这是我正在做的一个例子.
button = new Button(this); //here I am just checking if the button can come above the EditText button.setText("I am a button"); params.addRule(RelativeLayout.BELOW, editText.getId()); params.addRule(RelativeLayout.ALIGN_PARENT_ABOVE); relativeLayout.addView(button);
我根本无法进行对齐.
任何线索都非常感谢.
提前致谢.
button = new Button(this); //here I am just checking if the button can come above the EditText button.setText("I am a button"); params.addRule(RelativeLayout.BELOW, editText.getId()); params.addRule(RelativeLayout.ALIGN_PARENT_ABOVE); relativeLayout.addView(button, params);
addView method