Tell me how to programmatically assign a position to a button in android using linear layout. By default it takes the xtreme left position of the screen. Also i want to do it using Linear layout please do not suggest me using Relative layout. Following is my code
buttons_and_edittext=new LinearLayout(HelloAugmentedWorldActivity.this);
buttons_and_edittext = (LinearLayout)findViewById(R.id.linearLayout1);
buttons_and_edittextParameters = new LinearLayout.LayoutParams(120, 150);
button3 = new Button(this);
button3.setText("log");
buttons_and_edittext.addView(button3,
buttons_and_edittextParameters);
any help will be appreciated thanks
Please refer below link for add buttons into relative layout at fix position.
Android User Interface Design: Relative Layout
And Use Below Code also for that.
Button but1 = new Button(this);
RelativeLayout.LayoutParams params2 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params2.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
but1.setLayoutParams(params2);
but1.setText("Press Here!");
// give the button an id that we know
but1.setId(1001);
layout1.addView(but1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With