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
-
- <?XML Version="1.0" Encoding="UTF-8"?>
- <Linearlayout Xmlns: Android=Http://schemas.android.com/apk/res/android"
-
- Android: Orientation="Vertical"
-
- Android: layout_width="Fill_parent"
-
- Android: layout_height="Fill_parent"
-
- >
- <Slidingdrawer
-
- Android: ID="@ + ID/slidingdrawer"
-
- Android: layout_width="Fill_parent"
-
- Android: layout_height="Fill_parent"
-
- Android: Orientation="Vertical"
- Android: handle="@ + ID/handle"
-
- Android: Content="@ + ID/content">
-
- <Imagebutton
-
- Android: ID="@ + ID/handle"
- Android: layout_width="Wrap_content"
-
- Android: layout_height="Wrap_content"
-
- Android: SRC="@ Drawable/button_up"/>
-
- <Linearlayout
- Android: ID="@ + ID/content"
-
- Android: layout_width="Wrap_content"
-
- Android: layout_height="Wrap_content"
-
- Android: Background="# Ffffff">
-
- <Textview Android: Text="Ceshi"
-
- Android: ID="@ + ID/textview"
-
- Android: layout_width="Wrap_content"
- Android: layout_height="Wrap_content"/>
-
- </Linearlayout>
-
- </Slidingdrawer>
-
- </Linearlayout>
- PackageCom. dapp;
-
-
- ImportJava. util. arraylist;
-
- ImportJava. util. hashmap;
-
- ImportJava. util. List;
-
-
- ImportAndroid. App. activity;
-
- ImportAndroid. content. context;
-
- ImportAndroid. OS. Bundle;
-
- ImportAndroid. View. view;
- ImportAndroid. View. viewgroup;
-
- ImportAndroid. widget. baseadapter;
-
- ImportAndroid. widget. imagebutton;
-
- ImportAndroid. widget. slidingdrawer;
-
- ImportAndroid. widget. textview;
-
-
- Public ClassChoutiactivityExtendsActivity {
-
- PrivateSlidingdrawer mdrawer;
- PrivateImagebutton mbutton;
-
- PrivateTextview mtext;
-
- Private BooleanFlag;
-
- PrivateHashmap <string, Object> map;
-
-
- Public VoidOncreate (bundle savedinstancestate ){
- Super. Oncreate (savedinstancestate );
-
- Setcontentview (R. layout. Main );
-
-
- Mdrawer = (slidingdrawer) findviewbyid (R. Id. slidingdrawer );
-
- Mbutton = (imagebutton) findviewbyid (R. Id. Handle );
-
- Mtext = (textview) findviewbyid (R. Id. textview );
-
- Drawerlistener ();
- Getdata ();
-
- }
-
-
- Private VoidGetdata (){
-
- List NewArraylist
-
- For(IntI =0; I <10; I ++ ){
-
- Map =NewHashmap <string, Object> ();
-
- Map. Put ("Text","Ceshi");
-
- Listdata. Add (MAP );
- }
-
- }
-
-
- Private VoidDrawerlistener (){
-
- Mdrawer. setondraweropenlistener (NewSlidingdrawer. ondraweropenlistener (){
-
-
- @ Override
- Public VoidOndraweropened (){
-
- Flag =True;
-
- Mbutton. setimageresource (R. drawable. button_down );
-
- }
-
- });
-
- Mdrawer. setondrawercloselistener (NewSlidingdrawer. ondrawercloselistener (){
-
-
- @ Override
-
- Public VoidOndrawerclosed (){
-
- Flag =False;
- Mbutton. setimageresource (R. drawable. button_up );
-
- }
-
- });
-
-
- Mdrawer. setondrawerscrolllistener (NewSlidingdrawer. ondrawerscrolllistener (){
-
-
- @ Override
- Public VoidOnscrollstarted (){
-
- Mtext. settext ("End dragging");
-
- }
-
-
- @ Override
- Public VoidOnscrollended (){
-
- Mtext. settext ("Start dragging");
-
- }
-
- });
-
- }
-
-
- }