android custom layout

 

 

 

 

Activity class part of the code:
RelativeLayout rl = new RelativeLayout(this);

//Set the width and height of the RelativeLayout layout
RelativeLayout.LayoutParams relLayoutParams=new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);

TextView temp = new TextView(this);
temp .setId(1);
temp.setText("image");
rl.addView(temp);

TextView tv = new TextView(this);
tv.setText("text");
tv.setId (2);

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

param1.addRule(RelativeLayout.BELOW, 1);//This control is below the control whose id is 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);//This control is to the right of the control whose id is 1

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

 

 

 

 

 

 

 

 

 

 

Donate to developers

Driven by interest, I write 免费something with joy and sweat. I hope you like my work and can support it at the same time. Of course, if you have money to support a money field (the love sign in the upper right corner, support Alipay and PayPal donations), if you have no money to support a personal field, thank you.



 
 
 Thank you for your sponsorship, I will do better!

 

 

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326563841&siteId=291194637