The SlidingDrawer hides content outside the screen and allows you to drag a handle to display hidden content. Can be used in the request confirmation or rejection location
SlidingDrawer can be used vertically or horizontally. 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.
01 <SlidingDrawer
02 android: id = "@ + id/drawer"
03 android: layout_width = "match_parent"
04 android: layout_height = "match_parent"
05
06 android: handle = "@ + id/handle"
07 android: content = "@ + id/content">
08
09 <ImageView
10 android: id = "@ id/handle"
11 android: layout_width = "88dip"
12 android: layout_height = "44dip"/>
13
14 <GridView
15 android: id = "@ id/content"
16 android: layout_width = "match_parent"
17 android: layout_height = "match_parent"/>
18
19 </SlidingDrawer>
Iii. Internal class
Interface SlidingDrawer. OnDrawerCloseListener
Called when drawer (drawer) is closed
Interface SlidingDrawer. OnDrawerOpenListener
Called when drawer (drawer) is opened
Interface SlidingDrawer. OnDrawerScrollListener
Called when drawer (drawer) Slides (scroll)
Iv. XML attributes
Attribute name
Description
Android: allowSingleTap
Indicates 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: animateOnClick
Indicates whether the drawer is opened or closed as an animation when you click handle. The default value is true.
Android: bottomOffset
Handle's additional distance from the bottom of SlidingDrawer
Android: content
Content that identifies SlidingDrawer
Android: handle
Handle that identifies SlidingDrawer (such as a button)
Android: orientation
The direction of SlidingDrawer. It must be the following value:
Constant Value description
Horizontal 0 horizontal Alignment
Vertical 1 vertical Alignment
Android: topOffset
Handle's additional distance from the top of SlidingDrawer
5. Constants
Public static final int ORIENTATION_HORIZONTAL
(Translator's note: horizontal alignment)
Constant Value: 0 (0 × 00000000)
Public static final int ORIENTATION_VERTICAL
(Translator's note: vertical alignment)
Constant Value: 1 (0x00000001)
Vi. Constructor
Public SlidingDrawer (Context context, AttributeSet attrs)
Use the property set in xml to create a new SlidingDrawe
Parameters
Context
Attributes defined in attrs XML
Public SlidingDrawer (Context context, AttributeSet attrs, int defStyle)
Use the property set in xml to create a new SlidingDrawe
Parameters
Context
Attributes defined in attrs XML
DefStyle applies the style on this component.
VII. Public Methods
Public void animateClose ()
Close the animation drawer.
See
Close ()
Open ()
AnimateOpen ()
AnimateToggle ()
Toggle ()
Public void animateOpen ()
The animation effect opens the drawer.
See
Close ()
Open ()
AnimateOpen ()
AnimateToggle ()
Toggle ()
Public void animateToggle ()
Animation switching between opening and closing drawers
See
Close ()
Open ()
AnimateOpen ()
AnimateToggle ()
Toggle ()
Public void close ()
Close drawer now
See
Open ()
Toggle ()
AnimateClose ()
Public View getContent ()
Return the content of the drawer)
Return Value
Returns the view of the drawer content, which is identified by the "content" id in XML.
Public View getHandle ()
Return handle of the drawer
Return Value
Return to the handle view in the drawer, which is identified by the "handle" id in XML.
Public boolean isMoving ()
Whether the drawer is scroll or slide.
Return Value
Returns true if you scroll or slide; otherwise, returns false.
Public boolean isOpened ()
Whether the current drawer is fully opened
Return Value
If it is enabled, true is returned; otherwise, false is returned.
Public void lock ()
Lock scyclingdrawer and ignore touch events
See
Unlock ()
Public boolean onInterceptTouchEvent (MotionEvent event)
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.
(TRANSLATOR: This is really too troublesome and difficult to understand. I feel dizzy and find a good summary on the Internet to know what is going on. Here I will summarize it, remember this principle and you will be very clear:
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.
Related articles: 1. 2)
Parameters
Hierarchical Action events
Return Value
Returns true if a motion event is intercepted from the subview and sent to the current ViewGroup through onTouchEvent. The current target will receive the ACTION_CANCEL event and no other messages will be sent to it.
Public boolean onTouchEvent (MotionEvent event)
How to Implement touch screen events
Parameters
Event current event
Return Value
If the event is processed, true is returned; otherwise, false is returned.
Public void open ()
Open drawer now
See
Toggle ()
Close ()
AnimateOpen ()
Public void setOnDrawerCloseListener (s0000ingdrawer. OnDrawerCloseListener onDrawerCloseListener)
Bind a listener to the close event of the drawer
Parameters
Listener when the onDrawerCloseListener drawer is closed
Public void setOnDrawerOpenListener (s0000ingdrawer. OnDrawerOpenListener onDrawerOpenListener)
Bind a listener to the opening event of the drawer
Parameters
OnDrawerOpenListener authenticator when the drawer is opened
Public void setOnDrawerScrollListener (SlidingDrawer. OnDrawerScrollListener onDrawerScrollListener)
Bind a listener to the scroll event of the drawer. fling is also treated as a scroll event, which can trigger the close or open event of the drawer.
Parameters
Listener for notifications when onDrawerScrollListener starts or stops rolling (shrinking)
Public void toggle ()
Switch between open or closed drawers. Events are generated immediately.
See
Close ()
Open ()
AnimateOpen ()
AnimateToggle ()
Toggle ()
Public void unlock ()
Unlock SlidingDrawer to enable processing of touch events
Author: amigos_pop