Friday 15 February 2013

java - Overlapping buttons in android -



java - Overlapping buttons in android -

in android, trying add together buttons programatically, buttons added overlapping. code using this:

for(int = (int) 'a'; <= (int) 'z'; i++) { button button = new button(this); char letter = (char)i; string letteronbutton = character.tostring(letter); button.settext(letteronbutton); relativelayout rl = (relativelayout)findviewbyid(r.id.dynbuttons); layoutparams lp = new layoutparams(layoutparams.wrap_content,layoutparams.wrap_content); rl.addview(button,lp); }

it not throw button, see "z" button.

any thought on how prepare this?

as mentioned above linearlayout best solution, if u still want utilize relativelayout, seek setting id each button , inflate subsequent parameter right_of/below..as suggested above, parameter "layout_alignleft" produce same effect, i.e inflate buttons in same position

relativelayout rl = (relativelayout) findviewbyid(r.id.layout); int id = 0; (int = (int) 'a'; <= (int) 'z'; i++) { button button = new button(this); char letter = (char) i; string letteronbutton = character.tostring(letter); button.settext(letteronbutton); button.setid(i); layoutparams lp = new layoutparams(layoutparams.wrap_content, layoutparams.wrap_content); lp.addrule(relativelayout.below, id); rl.addview(button, lp); id = i; }

java android

No comments:

Post a Comment