Skip to content Skip to sidebar Skip to footer

How Can I Get A Smooth Move Using Timertask?

I used following code to move a image it works fine but while moving the image not perform a smooth moving. Can anyone find the problem in my code? handler = new Handler();

Solution 1:

TimerTask and Threads are not good choice for consistent UI changes.

  1. Create CustomView by entending SurfaceView .

  2. Manage some class variables for position of views.

  3. In onDraw() create view and update variables for next positioning .

  4. Wherever want to refresh manually, call invalidate.

Follow this tutorial for more help .

Solution 2:

ImageViewimg_animation= (ImageView) findViewById(R.id.imageView1);

    TranslateAnimationanimation=newTranslateAnimation(0.0f, 400.0f,0.0f, 0.0f);          //  new TranslateAnimation(xFrom,xTo, yFrom,yTo)
    animation.setDuration(5000);  // animation duration 
    animation.setRepeatCount(5);  // animation repeat count
    animation.setRepeatMode(2);   // repeat animation (left to right, right to left )//animation.setFillAfter(true);      

    img_animation.startAnimation(animation); 

Animation is the best smooth moving !! Try it !!

Post a Comment for "How Can I Get A Smooth Move Using Timertask?"