【发布时间】:2019-06-03 16:07:09
【问题描述】:
我已经有一种方法可以在屏幕的随机位置显示按钮,但它不适用于其他屏幕尺寸。我该怎么做(内部:r.nextInt())。
int buttonHeight;
int buttonWidth;
buttonHeight = button.getHeight();
buttonWidth = button.getWidth();
int xLeft = r.nextInt(480 - buttonHeight);
int yUp = r.nextInt(500 - buttonWidth);
int xRight = r.nextInt(670 + buttonHeight);
int yDown = r.nextInt(1400 + buttonWidth);
button.setX(xLeft);
button.setY(yUp);
button.setX(xRight);
button.setY(yDown);
我只是想让随机数适应每个屏幕尺寸。
【问题讨论】:
-
实际上几乎可以工作,唯一的问题是它有时会脱离屏幕。我不知道为什么。
-
在下面查看我的答案
标签: java android-studio android-studio-3.0