This article is from http://blog.csdn.net/hellogv/, the citation must be noted!
On Android to achieve similar launch drawer effect, we must first think of Slidingdrawer. Slidingdrawer is one of the official Android controls, the main character of this article is not it, but the folk control tool collection ~~~android-misc-widgets. Android-misc-widgets contains several widget:panel, Smoothbutton, Switcher, VirtualKeyboard, as well as some animated effects, this article mainly introduces the use of drawer container Panel. Android-misc-widgets's Google Project address:-widgets/http://code.google.com/p/android-misc, the panel in the Engineering code demonstrates the following:
This Panel control can easily achieve the drawer effect in different directions, which is more scalable than slidingdrawer!
In the process of using panel several times, found that the panel has a bug, will intermittently appear "flashing", that is, in the ontouchlistener inside the trigger Action_down, the drawer immediately pop up and then instantly recycled (version date is 3, 2009). Put the ontouchlistener of the original panel, that is, the following code:
[Java]View Plaincopyprint?
- Ontouchlistener Touchlistener = new Ontouchlistener () {
- int initx;
- int inity;
- Boolean setinitialposition;
- Public Boolean OnTouch (View V, motionevent event) {
- if (mstate = = state.animating) {
- //We are animating
- return false;
- }
- /LOG.D (TAG, "state:" + mstate + "x:" + event.getx () + "y:" + event.gety ());
- int action = Event.getaction ();
- if (action = = Motionevent.action_down) {
- if (mbringtofront) {
- BringToFront ();
- }
- INITX = 0;
- Inity = 0;
- if (mcontent.getvisibility () = = GONE) {
- //Since we know content dimensions we use factors here
- if (morientation = = VERTICAL) {
- inity = Mposition = = TOP? -1: 1;
- } Else {
- INITX = Mposition = = left? -1: 1;
- }
- }
- Setinitialposition = true;
- } Else {
- if (setinitialposition) {
- //Now we know content dimensions, so we multiply factors ...
- Initx *= mcontentwidth;
- Inity *= mcontentheight;
- //... and set initial panel ' s position
- Mgesturelistener.setscroll (INITX, inity);
- Setinitialposition = false;
- //For Offsetlocation we had to invert values
- INITX =-INITX;
- inity =-inity;
- }
- //Offset every Action_move & action_up event
- Event.offsetlocation (INITX, inity);
- }
- if (!mgesturedetector.ontouchevent (event)) {
- if (action = = motionevent.action_up) {
- //Tup up after scrolling
- Post (startanimation);
- }
- }
- return false;
- }
- };
To be replaced by:
[Java]View Plaincopyprint?
- Ontouchlistener Touchlistener = new Ontouchlistener () {
- float Touchx, touchy;
- Public Boolean OnTouch (View V, motionevent event) {
- if (mstate = = state.animating) {
- //We are animating
- return false;
- }
- int action = Event.getaction ();
- if (action = = Motionevent.action_down) {
- if (mbringtofront) {
- BringToFront ();
- }
- Touchx = Event.getx ();
- Touchy = Event.gety ();
- }
- if (!mgesturedetector.ontouchevent (event)) {
- if (action = = motionevent.action_up) {
- //Tup up after scrolling
- int size = (int) (Math.Abs (Touchx-event.getx ()) + Math
- . ABS (Touchy-event.gety ()));
- if (size = = Mcontentwidth | | size = = mcontentheight) {
- Mstate = state.about_to_animate;
- //log.e ("Size", string.valueof (size));
- //log.e (string.valueof (mcontentwidth), string.valueof (Mcontentheight));
- }
- Post (startanimation);
- }
- }
- return false;
- }
- };
Can fix this bug, and also realized the function of Onclicklistener, it is possible to delete the Onclicklistener of the original panel!
Android improves the 19th "multi-directional" drawer--turn