This article from http://blog.csdn.net/hellogv/, reference must indicate the source!
To achieve a drawer effect similar to launch on Android, you must first think of slidingdrawer. Slidingdrawer is one of the official Android controls. The main character of this article is not it, but a collection of Folk control tools ~~~ Android-MISC-widgets. Android-MISC-widgets contains several widgets: panel, smoothbutton, switcher, virtualkeyboard, and some animation effects. This article mainly introduces the usage of panel in drawer containers. Android-MISC-widgets's Google Project address:-widgets/http://code.google.com/p/android-misc. the demo Effect of panelin the project code is as follows:
This panel control can easily achieve drawer effects in different directions, which is more scalable than slidingdrawer!
In the process of using the Panel multiple times, a bug is found in the panel, which may flash intermittently, that is, after the action_down trigger in the ontouchlistener,The drawer pops up instantly and then recycles it instantly.(Version Date {
Function onclick ()
{
_ Cancelbubble = true
}
} "Href =" http://code.google.com/p/android-misc-widgets/source/browse/trunk/android-misc-widgets/src/org/miscwidgets/widget/Panel.java "> Feb 3, 2009 ). The ontouchlistener of the original panel, that is, the following code:
Ontouchlistener touchlistener = new ontouchlistener () {<br/> int initx; <br/> int inity; <br/> Boolean setinitialposition; <br/> Public Boolean ontouch (view V, motionevent event) {<br/> If (mstate = state. animating) {<br/> // We are animating <br/> return false; <br/>}< br/> // log. D (TAG, "state:" + mstate + "X:" + event. getx () + "Y:" + event. gety (); <br/> int action = event. getaction (); <br/> if (Ction = motionevent. action_down) {<br/> If (mbringtofront) {<br/> bringtofront (); <br/>}< br/> initx = 0; <br/> inity = 0; <br/> If (mcontent. getvisibility () = gone) {<br/> // since we may not know content dimensions we use factors here <br/> If (morientation = vertical) {<br/> inity = mposition = Top? -1: 1; <br/>}else {<br/> initx = mposition = left? -1: 1; <br/>}< br/> setinitialposition = true; <br/>}else {<br/> If (setinitialposition) {<br/> // now we know content dimensions, so we multiply factors... <br/> initx * = mcontentwidth; <br/> inity * = mcontentheight; <br/> //... and set initial panel's position <br/> mgesturelistener. setscroll (initx, inity); <br/> setinitialposition = false; <br/> // For offsetlocation we have to invert values <Br/> initx =-initx; <br/> inity =-inity; <br/>}< br/> // offset every action_move & action_up event <br/> event. offsetlocation (initx, inity); <br/>}< br/> If (! Mgesturedetector. ontouchevent (event) {<br/> If (Action = motionevent. action_up) {<br/> // Tup after scrolling <br/> post (startanimation); <br/>}< br/> return false; <br/>}< br/> };
Replace:
Ontouchlistener touchlistener = new ontouchlistener () {<br/> float touchx, touchy; </P> <p> Public Boolean ontouch (view V, motionevent event) {<br/> If (mstate = state. animating) {<br/> // We are animating <br/> return false; <br/>}</P> <p> int action = event. getaction (); <br/> If (Action = motionevent. action_down) {<br/> If (mbringtofront) {<br/> bringtofront (); <br/>}< br/> touchx = event. getx (); <br/> Touchy = event. Gety (); <br/>}</P> <p> If (! Mgesturedetector. ontouchevent (event) {<br/> If (Action = motionevent. action_up) {<br/> // Tup after scrolling <br/> int size = (INT) (math. ABS (touchx-event. getx () + math <br/>. ABS (touchy-event. gety (); </P> <p> If (size = mcontentwidth | size = mcontentheight) {<br/> mstate = state. about_to_animate; <br/> // log. E ("size", String. valueof (size); <br/> // log. E (string. valueof (mcontentwidth), String. valueof (mcontentheight); <br/>}</P> <p> post (startanimation); <br/>}< br/> return false; <br/>}< br/>}; <br/>
This bug can be fixed, and the onclicklistener function is also implemented. You can delete the onclicklistener of the original panel!