Not sure if it's the best way, but you can use padding to position elements in an absolute way. I think AbsoluteLayout is deprecated now, but you used to be able to use that to do what you want.
On Nov 27, 8:01 pm, babu <rkabhi1...@gmail.com> wrote: > 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en