Scyclingdrawer drawer effects for Android

Source: Internet
Author: User

The slidingdrawer hides content outside the screen and allows you to drag a handle to display hidden content.It consists of two sub-views: one is the handle dragged by the user, and the other is the content that changes with the drag ). Slidingdrawer should be used as the overwrite of the internal layout, that is, the slidingdrawer should use the framelayout or relativelayout layout internally. The size of slidingdrawer determines the space occupied when the content is displayed. Therefore, its size is generally defined as match_parent. In the XML layout, slidingdrawer must specify the handle and Content ID.

Where:

Android: allowsingletapIndicates whether the drawer can be opened or closed by clicking handle (if it is false, the user must just open/close the drawer by dragging, sliding, or using a trackball .) The default value is true.

Android: animateonclickIndicates whether the drawer is opened or closed as an animation when you click handle. The default value is true.

Android: bottomoffsetHandle's additional distance from the bottom of slidingdrawer

Android: ContentContent that identifies slidingdrawer

Android: handleHan that identifies slidingdrawer

This method can intercept all touch-screen events. It intercepts the events before they are passed to the subclass and obtains the ownership of the current gesture.

Pay attention to this method, because it has a very complex interaction with view. ontouchevent (motionevent) and needs to be implemented in the correct way. Events are accepted in the following order:
1. The down event is first transmitted to this method.
2. this down event will be processed by the ontouchevent () method of the current viewgroup or its subviews. That is to say, you should implement the ontouchevent () method and return true, you will continue to see the transfer of the remaining events (instead of looking for a parent view to process it ). Similarly, return true from ontouchevent (). You will not receive any subsequent events in onintercepttouchevent (), and all events will be processed by ontouchevent.
3. If the current method returns false, all subsequent events (including registered events as of the end) will be uploaded to the ontouchevent () method. As of and including the final registration.
4. if true is returned here, no event is received: the target view receives the same event but is accompanied by the action_cancel event, and all the further events will be passed to your ontouchevent () method and will not appear here.

 

You can find related annotations on the Internet as follows:

1. onintercepttouchevent () is used to process events (similar to preprocessing, but it can also not be processed) and change the event transmission direction, that is, to determine whether to allow the touch event to continue downward (sub-Control) if yes, but true is returned (the event will be processed in the current viewgroup), the path to the next pass is truncated (all child controls will not be involved in the touch event ), at the same time, the event is passed to the ontouchevent () processing of the current control; if false is returned, the event is handed over to the onintercepttouchevent () processing of the Child control.
2. ontouchevent () is used to process events. The returned value determines whether the current control consumes the event (consume). That is to say, after the current control finishes processing the touch event, whether to allow the touch event to be passed up (parent control). If the value of true is returned, the parent control does not have to handle the touch event on its own.

 

Let's take a look at this.

First paste the main. xmlCode, The image needed in the Code is resolved by yourself

  1. <?XML Version="1.0" Encoding="UTF-8"?>
  2. <Linearlayout Xmlns: Android=Http://schemas.android.com/apk/res/android"
  3. Android: Orientation="Vertical"
  4. Android: layout_width="Fill_parent"
  5. Android: layout_height="Fill_parent"
  6. >
  7. <Slidingdrawer
  8. Android: ID="@ + ID/slidingdrawer"
  9. Android: layout_width="Fill_parent"
  10. Android: layout_height="Fill_parent"
  11. Android: Orientation="Vertical"
  12. Android: handle="@ + ID/handle"
  13. Android: Content="@ + ID/content">
  14. <Imagebutton
  15. Android: ID="@ + ID/handle"
  16. Android: layout_width="Wrap_content"
  17. Android: layout_height="Wrap_content"
  18. Android: SRC="@ Drawable/button_up"/>
  19.  <Linearlayout
  20. Android: ID="@ + ID/content"
  21. Android: layout_width="Wrap_content"
  22. Android: layout_height="Wrap_content"
  23. Android: Background="# Ffffff">
  24. <Textview Android: Text="Ceshi"
  25. Android: ID="@ + ID/textview"
  26. Android: layout_width="Wrap_content"
  27. Android: layout_height="Wrap_content"/>
  28.  </Linearlayout>
  29. </Slidingdrawer>
  30. </Linearlayout>

 

 

  1. PackageCom. dapp;
  2. ImportJava. util. arraylist;
  3. ImportJava. util. hashmap;
  4. ImportJava. util. List;
  5. ImportAndroid. App. activity;
  6. ImportAndroid. content. context;
  7. ImportAndroid. OS. Bundle;
  8. ImportAndroid. View. view;
  9. ImportAndroid. View. viewgroup;
  10. ImportAndroid. widget. baseadapter;
  11. ImportAndroid. widget. imagebutton;
  12. ImportAndroid. widget. slidingdrawer;
  13. ImportAndroid. widget. textview;
  14. Public ClassChoutiactivityExtendsActivity {
  15. PrivateSlidingdrawer mdrawer;
  16. PrivateImagebutton mbutton;
  17. PrivateTextview mtext;
  18. Private BooleanFlag;
  19. PrivateHashmap <string, Object> map;
  20. Public VoidOncreate (bundle savedinstancestate ){
  21. Super. Oncreate (savedinstancestate );
  22. Setcontentview (R. layout. Main );
  23. Mdrawer = (slidingdrawer) findviewbyid (R. Id. slidingdrawer );
  24. Mbutton = (imagebutton) findviewbyid (R. Id. Handle );
  25. Mtext = (textview) findviewbyid (R. Id. textview );
  26. Drawerlistener ();
  27. Getdata ();
  28. }
  29. Private VoidGetdata (){
  30. List NewArraylist
  31. For(IntI =0; I <10; I ++ ){
  32. Map =NewHashmap <string, Object> ();
  33. Map. Put ("Text","Ceshi");
  34. Listdata. Add (MAP );
  35. }
  36. }
  37. Private VoidDrawerlistener (){
  38. Mdrawer. setondraweropenlistener (NewSlidingdrawer. ondraweropenlistener (){
  39. @ Override
  40. Public VoidOndraweropened (){
  41. Flag =True;
  42. Mbutton. setimageresource (R. drawable. button_down );
  43. }
  44. });
  45. Mdrawer. setondrawercloselistener (NewSlidingdrawer. ondrawercloselistener (){
  46. @ Override
  47. Public VoidOndrawerclosed (){
  48. Flag =False;
  49. Mbutton. setimageresource (R. drawable. button_up );
  50. }
  51. });
  52. Mdrawer. setondrawerscrolllistener (NewSlidingdrawer. ondrawerscrolllistener (){
  53. @ Override
  54. Public VoidOnscrollstarted (){
  55. Mtext. settext ("End dragging");
  56. }
  57. @ Override
  58. Public VoidOnscrollended (){
  59. Mtext. settext ("Start dragging");
  60. }
  61. });
  62. }
  63. }

 

Related Article

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.