Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Use this code in you java file </p> <p>public class MainActivity extends Activity {</p> <pre><code>@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); RelativeLayout rl = (RelativeLayout) findViewById(R.id.rl); LinearLayout ll = new LinearLayout(this); LinearLayout.LayoutParams layout_params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); LinearLayout.LayoutParams box_params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 40); LinearLayout.LayoutParams btn_params = new LinearLayout.LayoutParams(120, 40); ll.setOrientation(LinearLayout.VERTICAL); EditText et1 = new EditText(MainActivity.this); et1.setHint("Enter User name"); EditText et2 = new EditText(MainActivity.this); et2.setHint("Enter speed"); Button btn= new Button(MainActivity.this); btn.setText("Back to Game"); btn.setGravity(Gravity.CENTER_HORIZONTAL); ll.addView(et1, box_params); ll.addView(et2, box_params); ll.addView(btn, btn_params); ll.setGravity(Gravity.CENTER); rl.addView(ll,layout_params ); } </code></pre> <p>}</p> <p>You will get required output but it is prefer to use xml file until you don't need dynamic changes in your UI. It is easy to maintain code and design screens using xml files and if there is no need of large dynamic changes you should use xml files. Through Xml files you can check you code on different resolution through graphical representation of code. You can create a xml file in layout folder and can link it to your activity. It is easy, time saving and provide you more accurate designs... :) Please check screen shot for dynamic creation of your required design. </p> <p><img src="https://i.stack.imgur.com/Bhbii.png" alt="enter image description here"></p> <p>Happy Coding !!!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload