mercredi 25 novembre 2015

How can I move the button?

I am new to animations in android. I was wondering, is there a way to keep a button moving around the screen, bouncing off the walls, until it gets clicked? I was thinking to do something like this:

    while(!clicked){
    //Run code to move button
        }
  button.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
    clicked = true;
        }
    );

And to make it random, do something like this:

Random r = new Random();
btnCount.animate().xBy(r.nextInt(10)+1).yBy(r.nextInt(10)+1);

But that doesn't work, and nothing happens. I have thoroughly searched the android docs and other stack exchange pages, but they lack in detail, which is why I have come here to get help from the professionals.

What is the best way to do this animation?

Thanks,

Ruchir




Aucun commentaire:

Enregistrer un commentaire