Android: How do I randomly place an array of buttons in an activity? -


i wondering how "randomly" place array of buttons in relativelayout?

is possible space buttons around entire view?

thanks help! tried using setx() , sety() float numbers , i'm unsure how place buttons in proportion size of screen.

you can add layout margins buttons. margins interpreted not relative each other frame, in fact position buttons.

to set margins have set view's layout params:

relativelayout.layoutparams params = new relativelayout.layoutparams(layoutparams.wrap_content,layoutparams.wrap_content); random random = new random(); params.leftmargin = random.nextint(100); params.topmargin = random.nextint(100); button.setlayoutparams(params); 

however may cause buttons overlap, or outside activity, it's best not use entirely random values positions perform checks overlapping , set random ranges according device resolution , button size.

to device display size:

display display= activity.getwindowmanager().getdefaultdisplay(); int width = display.getwidth(); int height = display.getheight(); 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -