I'm trying to set a framelayouts position to a random value onclick for a game I'm creating. I'm very new to java and although I've got the random numbers, I can't find how to set the framelayouts position to those random numbers' value. Here's my uncompleted code. Let me know if you want me to clarify something!
public class MainActivity extends AppCompatActivity {
private int rWidth = (int) Math.round(Math.random() * WIDTH);
private int rHeight = (int) Math.round(Math.random() * HEIGHT);
@Override
public void onStart(){
super.onStart();
private int WIDTH = this.getResources().getDisplayMetrics().widthPixels;
private int HEIGHT = this.getResources().getDisplayMetrics().heightPixels;
final FrameLayout mainObject = (FrameLayout) findViewById(R.id.mainObject);
mainObject.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//Here's where I want to change the position!
}
});
}
}
Thanks!
Aucun commentaire:
Enregistrer un commentaire