I need to create a custom toggle-silder widget, like in the iphone, things like on-off items etc... For the task i chose to inherit from LinearLayout, define it as Vertical and grab some xml attributes like the drawables that will be using for the buttons (one for on, one for off) and i just place two Views with the drawables as their backgrounds. Now the issues i'm facing are:
ok if we take a look on this page: http://developer.android.com/guide/topics/graphics/view-animation.html
we can see that we have simple way to create the animation, once onClick or onTouchStart is discovered (if not already processing), start the animation preloaded from the xml and disable touch on the View until animation ends(you cann add animation listener to animation object). you should make sure fillAfter is true so the values will stick after animation ends.
the only issue with it is that it doesn't allow dragging like in iphone, possible solution would be to allow dragging up to certain delta and if that delta is passed ignore any onTouchMove events, disable touch and start the animation.
ofcourse deltas and animations should be updated according to the state of the button. i might post code soon.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.