• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Adding a Button to a view created from XML

 
Monu Tripathi
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[I am bad at layouting and XML..]

I have a XML that defines a screen layout(couple of edittext,textview boxes). I have done setContentView(Resid) and am displaying the view on the screen. Now, I want to add a couple of buttons at the bottom of the screen and "preferably" at the center.

I created buttons in code and when i added them on the screen. Both the buttons got added over one another and at the top left of the screen. I figure this could be a layout problem. Can anyone help?


Please share links that shows how to draw a view ( by mixing XML layouting and view created in code) if you have..

Thanks.


 
Ed Burnette
Author
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're probably not adding them to the right parent, or perhaps you're not setting the LayoutParams correctly. See section 8.3, Bird's-Eye View for an example, or here's a direct link to the code:

http://media.pragprog.com/titles/eband/code/MyMap/src/org/example/mymap/MyMap.java

If that doesn't help, post your XML and Java code here for more advice.
 
Bharath Jagdish
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Monu,

I think you are using Relative layout. Specify the parameters for alignment of the buttons. For example your want the button below the text field, then you have attributes like layout_alignBelow to which you can give the reference of the text field. (this is wrt xml) Refer the below link for the attributes.

http://developer.android.com/reference/android/widget/RelativeLayout.html

To make your life easier, use the below link which gives you an interface to create layouts by drag and drop of the UI elements.

http://www.droiddraw.org/

If any further help required, do post it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic