Android improves the 19th "multi-directional" drawer--turn

Source: Internet
Author: User
Tags gety

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?
  1. Ontouchlistener Touchlistener = new Ontouchlistener () {
  2. int initx;
  3. int inity;
  4. Boolean setinitialposition;
  5. Public Boolean OnTouch (View V, motionevent event) {
  6. if (mstate = = state.animating) {
  7. //We are animating
  8. return false;
  9. }
  10. /LOG.D (TAG, "state:" + mstate + "x:" + event.getx () + "y:" + event.gety ());
  11. int action = Event.getaction ();
  12. if (action = = Motionevent.action_down) {
  13. if (mbringtofront) {
  14. BringToFront ();
  15. }
  16. INITX = 0;
  17. Inity = 0;
  18. if (mcontent.getvisibility () = = GONE) {
  19. //Since we know content dimensions we use factors here
  20. if (morientation = = VERTICAL) {
  21. inity = Mposition = = TOP?  -1: 1;
  22. } Else {
  23. INITX = Mposition = = left?  -1: 1;
  24. }
  25. }
  26. Setinitialposition = true;
  27. } Else {
  28. if (setinitialposition) {
  29. //Now we know content dimensions, so we multiply factors ...
  30. Initx *= mcontentwidth;
  31. Inity *= mcontentheight;
  32. //... and set initial panel ' s position
  33. Mgesturelistener.setscroll (INITX, inity);
  34. Setinitialposition = false;
  35. //For Offsetlocation we had to invert values
  36. INITX =-INITX;
  37. inity =-inity;
  38. }
  39. //Offset every Action_move & action_up event
  40. Event.offsetlocation (INITX, inity);
  41. }
  42. if (!mgesturedetector.ontouchevent (event)) {
  43. if (action = = motionevent.action_up) {
  44. //Tup up after scrolling
  45. Post (startanimation);
  46. }
  47. }
  48. return false;
  49. }
  50. };

To be replaced by:

[Java]View Plaincopyprint?
  1. Ontouchlistener Touchlistener = new Ontouchlistener () {
  2. float Touchx, touchy;
  3. Public Boolean OnTouch (View V, motionevent event) {
  4. if (mstate = = state.animating) {
  5. //We are animating
  6. return false;
  7. }
  8. int action = Event.getaction ();
  9. if (action = = Motionevent.action_down) {
  10. if (mbringtofront) {
  11. BringToFront ();
  12. }
  13. Touchx = Event.getx ();
  14. Touchy = Event.gety ();
  15. }
  16. if (!mgesturedetector.ontouchevent (event)) {
  17. if (action = = motionevent.action_up) {
  18. //Tup up after scrolling
  19. int size = (int) (Math.Abs (Touchx-event.getx ()) + Math
  20. . ABS (Touchy-event.gety ()));
  21. if (size = = Mcontentwidth | | size = = mcontentheight) {
  22. Mstate = state.about_to_animate;
  23. //log.e ("Size", string.valueof (size));
  24. //log.e (string.valueof (mcontentwidth), string.valueof (Mcontentheight));
  25. }
  26. Post (startanimation);
  27. }
  28. }
  29. return false;
  30. }
  31. };

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.