SlidingDrawer hides content outside the screen and allows users to display hidden content through handle. It can slide vertically or horizontally. It consists of two views. One is the handle that can be dragged, and the other is the View that hides the content. the controls in the layout must be set, and handle and content must be specified in the layout file.
1. layou file Layout
Copy codeThe Code is as follows: <LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: orientation = "vertical">
<TextView
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "@ string/hello_world"/>
<SlidingDrawer
Android: id = "@ + id/slidingdrawer"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: content = "@ + id/content"
Android: handle = "@ + id/handle"
Android: orientation = "vertical">
<Button
Android: id = "@ + id/handle"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "SlidingDraser"/>
<LinearLayout <! -- Hidden content -->
Android: id = "@ + id/content"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: background = "#00 ffaa">
<Button
Android: id = "@ + id/button"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "Button"/>
<EditText
Android: id = "@ + id/editText"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"/>
</LinearLayout>
</SlidingDrawer>
</LinearLayout>
2. The following is the interface after running the program.
In addition, you can add files to drawable.
Copy codeThe Code is as follows:
<? Xml version = "1.0" encoding = "UTF-8"?>
<Selector xmlns: android = "http://schemas.android.com/apk/res/android">
<Item android: state_window_focused = "false" android: state_enabled = "true" android: drawable = "@ drawable/handle_normal"/>
<Item android: state_pressed = "true" android: drawable = "@ drawable/handle_pressed"/>
<Item android: state_focused = "true" android: state_enabled = "true" android: drawable = "@ drawable/handle_focused"/>
<Item android: state_enabled = "true" android: drawable = "@ drawable/handle_normal"/>
<Item android: state_focused = "true" android: drawable = "@ drawable/handle_focused"/>
</Selector>
Summary:
1. Important attributes
Android: allowSingleTap: Indicates whether to enable or disable the function through handle.
Android: animateOnClick: Indicates whether an animation is required when the user presses the handle to open or close the animation.
Android: content: hidden content
Android: handle (handle)
2. Important Methods
AnimateClose (): animation is implemented when the animation is disabled.
Close (): close immediately
GetContent (): Get content
IsMoving (): Indicates whether SlidingDrawer is moving.
IsOpened (): Indicates whether SlidingDrawer is enabled.
Lock (): block touch events.
SetOnDrawerCloseListener (SlidingDrawer. OnDrawerCloseListener onDrawerCloseListener): called when SlidingDrawer is disabled
SetOnDrawerOpenListener
SetOnDrawerScrollListener
Unlock (): unblocks touch events.
Toggle (): Switch the s0000ingdrawer of the opened and closed drawers.