0

I am creating an Android Flappy Bird clone, but I don't know how to make a imageView move smoothly? Here is what I have done so far.

public void up(final ImageView i){


    CountDownTimer start = new CountDownTimer(100, 100) {
        @Override
        public void onTick(long millisUntilFinished) {
            i.setY(i.getY() - 10);
        }

        @Override
        public void onFinish() {
            i.setY(i.getY() - 10);
        }
    }.start();
}

Is there any other way to do this?

Jonas Czech
  • 12,018
  • 6
  • 44
  • 65
OAJJ
  • 35
  • 7
  • 2
    Use View.animate( *property* ). Or an ObjectAnimator. – Submersed Jun 02 '15 at 14:15
  • As an aside, you should probably look into using canvas instead of actual views. The redraw overhead for what you want to accomplish is pretty extreme if you use just regular views. – Elli White Jun 02 '15 at 14:44

1 Answers1

0

you can use animate() method to do the so

setduration acc to your need..

public void up(final ImageView i){


CountDownTimer start = new CountDownTimer(100, 100) {
    @Override
    public void onTick(long millisUntilFinished) {
        //i.setY(i.getY() - 10);
        i.animate().translationYBy(i.getY() - 10).setDuration(1000);
    }

    @Override
    public void onFinish() {
        //i.setY(i.getY() - 10);
        i.animate().translationYBy(i.getY() - 10).setDuration(1000);
    }
}.start();

}

Angad Tiwari
  • 1,738
  • 1
  • 12
  • 23