我有以下代码,将 textCheckedView 添加到相对布局中:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
final RelativeLayout rlayout = (RelativeLayout) findViewById(R.id.relativeLayout1);
final RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
p.addRule(RelativeLayout.ALIGN_PARENT_TOP);
final Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
int ids=0;
public void onClick(View v) {
String test ="test";
ids++;
final AlarmCheckedTextView checkedTV = createButton(test,ids);
checkedTV.setVisibility(1);
p.addRule(RelativeLayout.BELOW,checkedTV.getId());
rlayout.addView(checkedTV,p);
}
});
}
private CustomCheckedTextView createButton(String text, int id)
{
final CustomCheckedTextView checkedTV = new CustomCheckedTextView(this,text);
checkedTV.setId(id);
return checkedTV;
}
}
但是我CustomCheckedTextView
在RelativeLayout
点击Button
. 我的意思是所有内容都已成功添加,但都在一个地方。如何以编程方式添加低于以前的元素?