Hi,
How do I set the location of buttons/other views programmatically?
Below is my program snippet in the onCreate() method of my activity.
//Create two buttons
Button button1 = new Button(this);
Button button2 = new Button(this);
//Create layout params. Here, don't know how to
//set the location (relative location or X ,Y)
LayoutParams params = new LayoutParams
(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
button1.setLayoutParams(params);
button1.setText("Click this first");
button2.setLayoutParams(params);
button2.setText("Click this next");
//Create relativelayout
RelativeLayout layout = new RelativeLayout(this);
RelativeLayout.LayoutParams layoutparams = new
RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT,10,10);
//Add buttons to layout
layout.addView(button1, layoutparams);
layout.addView(button2, layoutparams);
//Set layout as content of activity
setContentView(layout);
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en