Implementation of Android SlidingDrawer drawer Effect

Source: Internet
Author: User

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.

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.