Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Adding a Button to a view created from XML

 
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.


 
Author
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.
 
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.
 
I'm gonna teach you a lesson! Start by looking at this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic