// Moves the actual button public void moveButton() { ImageButton charButton = (ImageButton) findViewById(R.id.goodIcon); RelativeLayout gameLayout = (RelativeLayout) findViewById(R.id.gameLayout); int width = gameLayout.getWidth(); int height = gameLayout.getHeight(); charButton.setImageDrawable(x); Random buttonPlace = new Random(); int buttonY = buttonPlace.nextInt(height - 100) + 100; int buttonX = buttonPlace.nextInt(width - 50) + 50; charButton.setX(buttonX); charButton.setY(buttonY); }
public void badCreate() { if (destroyBomb != null) { destroyBomb.cancel(); } DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); int width = displayMetrics.widthPixels; int height = displayMetrics.heightPixels; ImageButton altbutton = (ImageButton) findViewById(R.id.badIcon); altbutton.setVisibility(View.VISIBLE); altbutton.setClickable(true); Random r2 = new Random(); int Button2H = r2.nextInt(width - 400); int Button2W = r2.nextInt(height - 400); altbutton.setX(Button2H); altbutton.setY(Button2W); destroyBomb = new CountDownTimer(3000, 1000) { public void onTick(long millisUntilFinished) {} public void onFinish() { destroyBad(); } }.start(); }