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.
Create CustomView by entending SurfaceView .
Manage some class variables for position of views.
In onDraw() create view and update variables for next positioning .
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?"