I have a screen with 4 seek bars ( As shown in the image below) . If the user moves B,C or D I calculate the average of the three and setProgress of A to the average. That was the easy part . What I would like to do is animate the progress bar A such that it does not jump in one shot (for eg from 25-75 ).
What are the recommended ways to animate A? I got a simple animation up but I am calling a TimerTask every 50ms to increment or decrement A by a unit value till I reach the required position. But its not very efficient.
Note: I have a custom Seekbar object using which I have created seekBar's A,B,C & D. Sorry I cant really share the code but will be happy to clarify anything.
If you are using Honeycomb then you can use ViewPropertyAnimator http://android-developers.blogspot.com/2011/05/introducing-viewpropertyanimator.html
The animation before 3.0 is quite limited but as an alternative to your method you could use an animation listener:
Don't forget to call setFillAfter(boolean fillAfter) because the animation <3.0 doesn't actually move the view. It just gives the illusion that the view has moved. Important distinction if you still want the seekbar to continue to receive touches.
This works on any Android version, without using any animations.
I guess its too late. But I found a way to achieve this using ValueAnimator.
I reduced the number of iterations by iterating the timer task over an exponential function instead of unit increments. Still hoping for better answers :-)
I have done it using
ObjectAnimator
.I needed code that was just like what @sidhanshu_udawat had done. That was a great base to start from. Big win because it runs on its own thread. Thanks for that example.
However, when I took that code and tried it there was an issue that it would increment up and then stop.
I altered the code (pasted below) and now if you send in your seekbar with code like the following you will see that the seekbar animates up and down the scale.
isRunning - Control From Your Activity
Also, I needed to stop the animation when someone clicked a button so I added the boolean isRunning as a member on my Activity. Now when they click the button, I set isRunnig to false and the SeekBar stops.
Set up your SeekBar like the following and then call the method: