addroid 自定义布局

 

 

 

 

Activity类部分代码:
RelativeLayout rl = new RelativeLayout(this);

//设置RelativeLayout布局的宽高
RelativeLayout.LayoutParams relLayoutParams=new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);

TextView temp = new TextView(this);
temp .setId(1);
temp.setText(“图片”);
rl.addView(temp);

TextView tv = new TextView(this);
tv.setText(“文字”);
tv.setId(2);

LayoutParams param1 = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);

param1.addRule(RelativeLayout.BELOW, 1);//此控件在id为1的控件的下边
rl.addView(tv,param1);

Button update = new Button(this);
update.setText(Button);

LayoutParams param2 = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
param2.addRule(RelativeLayout.RIGHT_OF, 1);//此控件在id为1的控件的右边

rl.addView(update,param2);
this.addView(rl, relLayoutParams);

 

你可能感兴趣的:(android,自定义,布局)