You only need to copy the code to the oncreate method to run it.
Java code
- RelativeLayout rl = new RelativeLayout (this );
- Button btn1 = new Button (this );
- Btn1.setText ("----------------------");
- Btn1.setId (1 );
- RelativeLayout. LayoutParams lp1 = new RelativeLayout. LayoutParams (ViewGroup. LayoutParams. WRAP_CONTENT, ViewGroup. LayoutParams. WRAP_CONTENT );
- Lp1.addRule (RelativeLayout. ALIGN_PARENT_TOP );
- Lp1.addRule (RelativeLayout. CENTER_HORIZONTAL, RelativeLayout. TRUE );
- // Btn1 is located at the top of the parent View and horizontally centered in the parent View
- Rl. addView (btn1, lp1 );
- Button btn2 = new Button (this );
- Btn2.setText ("| \ n | ");
- Btn2.setId (2 );
- RelativeLayout. LayoutParams lp2 = new RelativeLayout. LayoutParams (ViewGroup. LayoutParams. WRAP_CONTENT, ViewGroup. LayoutParams. WRAP_CONTENT );
- Lp2.addRule (RelativeLayout. BELOW, 1 );
- Lp2.addRule (RelativeLayout. ALIGN_LEFT, 1 );
- // Btn2 is located below btn1 and alignment to the left of btn1
- Rl. addView (btn2, lp2 );
- Button btn3 = new Button (this );
- Btn3.setText ("| \ n | ");
- Btn3.setId (3 );
- RelativeLayout. LayoutParams lp3 = new RelativeLayout. LayoutParams (ViewGroup. LayoutParams. WRAP_CONTENT, ViewGroup. LayoutParams. WRAP_CONTENT );
- Lp3.addRule (RelativeLayout. BELOW, 1 );
- Lp3.addRule (RelativeLayout. RIGHT_OF, 2 );
- Lp3.addRule (RelativeLayout. ALIGN_RIGHT, 1 );
- // Btn3 is located at the bottom of btn1, right of btn2, and right of btn3 is aligned with the right of btn1 (to be expanded)
- Rl. addView (btn3, lp3 );
- Button btn4 = new Button (this );
- Btn4.setText ("--------------------------------------------");
- Btn4.setId (4 );
- RelativeLayout. LayoutParams lp4 = new RelativeLayout. LayoutParams (ViewGroup. LayoutParams. WRAP_CONTENT, ViewGroup. LayoutParams. WRAP_CONTENT );
- Lp4.addRule (RelativeLayout. BELOW, 2 );
- Lp4.addRule (RelativeLayout. CENTER_HORIZONTAL, RelativeLayout. TRUE );
- // Btn4 is located below btn2 and horizontally centered in the parent Veiw
- Rl. addView (btn4, lp4 );
- SetContentView (rl );