简体   繁体   中英

Android widget slide animation

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:

  1. i can catch onKeyDown and onTouchEvent to discover swipe and right-left-fire events so i'll switch states for the button, but i do wonder if there is a swipe event read in the android system onSwipe or should i try messing with the GestureDetector ?
  2. i want the sliding to be animated, i have no idea how to do that, any ideas where to start looking ?

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM