How can I as easy as possible set the position of my Button to a random place?
I’ve tryed to use this: (My screen resolution is 800×480)
Button btn = (Button) findViewById(R.id.button1);
Random r = new Random();
int x = r.nextInt(480);
int y = r.nextInt(800);
btn.setX(x);
btn.setY(y);
But when i use this, it seems that the button some times get located outside my application or so? is it possible to prevent this and keep the button inside the app?
Pretty sure your problem is you are not accounting for the width and height of the button, and so if it randoms to 480*800 it will be off the screen. Try something similar to: