| Author |
Adding a Button to a view created from XML
|
Monu Tripathi
Rancher
Joined: Oct 12, 2008
Posts: 1365
|
|
[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.
|
[List of FAQs] | [Android FAQ] | [My Blog] | [Samuh Varta]
|
 |
Ed Burnette
Author
Ranch Hand
Joined: Jun 10, 2003
Posts: 142
|
|
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.
|
Ed Burnette, Author of Hello Android
Blog: ZDNet's Dev Connection - Twitter: @eburnette
|
 |
Bharath Jagdish
Greenhorn
Joined: Mar 13, 2009
Posts: 5
|
|
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.
|
 |
 |
|
|
subject: Adding a Button to a view created from XML
|
|
|