我有一个按钮随机位置的方法:
public void randomButton(Button btn) {
LayoutParams absParams = (LayoutParams) btn.getLayoutParams();
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
absParams.leftMargin = btn.getWidth() + new Random().nextInt(displaymetrics.widthPixels - 2 * btn.getWidth());
absParams.topMargin = btn.getHeight() + new Random().nextInt(displaymetrics.heightPixels - 3 * btn.getHeight());
btn.setLayoutParams(absParams);
}
可以显示这样的多个按钮,但不能在它们之间交错?