草庐IT

java - 为按钮生成随机位置

我正在制作一个简单的游戏。我有6个按钮,每次我都想在不同位置随机播放它们。所以我做了一个简单的方法来实现这个。privatevoidchangeButtonPlace(ImageViewbutton){Randomr=newRandom();intnewXloc=r.nextInt(getScreenWidth()-(2*button.getLayoutParams().width));intnewYloc=r.nextInt(getScreenHeight()-(3*button.getLayoutParams().height));button.setX(newXloc);butt