In Android, you can customize classes and inherit from container classes such as viewgroup to display the layout you need.
If you add a control to viewgroup but it cannot be displayed, the following example can be used for reference.
(Mainly to implement the onlayout () method. In this method, perform measure () for each sub-control and then layout it .)
Package COM. arui; <br/> Import android. content. context; <br/> Import android. util. log; <br/> Import android. view. view; <br/> Import android. view. viewgroup; <br/> Import android. widget. button; <br/>/** <br/> * example for using viewgroup. <br/> * @ author http://blog.csdn.net/arui319 <br/> * @ version 2010/09/07 <br/> */<br/> public class myviewgroup extends viewgroup {<br/> Public myviewgroup (context) {<br/> super (context); <br/> This. initothercomponent (context); <br/>}< br/> private void initothercomponent (context) {<br/> button abtn = new button (context ); <br/> // Set ID 1 <br/> abtn. setid (1); <br/> abtn. settext ("a btn"); <br/> This. addview (abtn); <br/> button bbtn = new button (context); <br/> // Set ID 2 <br/> bbtn. setid (2); <br/> bbtn. settext ("B BTN"); <br/> This. addview (bbtn); <br/>}< br/> @ override <br/> protected void onlayout (Boolean changed, int L, int T, int R, int B) {<br/> int childcount = getchildcount (); <br/> for (INT I = 0; I <childcount; I ++) {<br/> View child = getchildat (I); <br/> switch (child. GETID () {<br/> case 1: <br/> // 1 is abtn <br/> log. D ("myviewgroup", "btn1 setting"); <br/> child. setvisibility (view. visible); <br/> child. measure (R-L, B-T); <br/> child. layout (0, 0, child. getmeasuredwidth (), Child <br/>. getmeasuredheight (); <br/> break; <br/> case 2: <br/> // 2 is bbtn <br/> log. D ("myviewgroup", "btn2 setting"); <br/> child. setvisibility (view. visible); <br/> child. measure (R-L, B-T); <br/> child. layout (0, 50, child. getmeasuredwidth (), Child <br/>. getmeasuredheight () + 50); <br/> break; <br/> default: <br/> // <br/>}< br/>