I only found ways to change the position of a button when clicking the same button. However, I simply can't find a way to change the position of a button when clicking an image button (different button). When changing their positions, the buttons only position at random at the upper landscape screen and not overlapping one another. Anyone can help?
Activity code:
public class keyboard extends AppCompatActivity implements View.OnClickListener {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_keyboard);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
Button buttons[] = new Button[5];
text = findViewById(R.id.txt);
money = findViewById(R.id.money_display);
countdown = findViewById(R.id.countdown);
buttons[0] = findViewById(R.id.bt1);
buttons[0].setOnClickListener(this);
buttons[1] = findViewById(R.id.bt2);
buttons[1].setOnClickListener(this);
buttons[2] = findViewById(R.id.bt3);
buttons[2].setOnClickListener(this);
buttons[3] = findViewById(R.id.bt4);
buttons[3].setOnClickListener(this);
buttons[4] = findViewById(R.id.bt5);
buttons[4].setOnClickListener(this);
imagebutton = findViewById(R.id.Imgbtn);
}
@Override
public void onClick(View v) {
Random rand = new Random();
View decorView = getWindow().getDecorView();
int screenWidth = decorView.getWidth();
int screenHeight = decorView.getHeight();
v.setX(rand.nextInt(screenWidth - v.getWidth()));
v.setY(rand.nextInt(screenHeight - v.getHeight()));
imagebutton.setOnClickListener(new View.OnClickListener()
}
@Override
public void onClick (View view) {
//
}