Scyclingdrawer drawer effects for Android

Source: Internet
Author: User

Slidingdrawer is newly added from SDK 1.5 to implement the drawer Effect of launcher. The slidingdrawer configuration adopts the horizontal or vertical expansion (Android: Orientation) mode. in XML, the Android: handle and Android: content must be specified, the former entrusts the image to be expanded (layout configuration), and the latter is the layout to be expanded
Content.

Show effect when shrinking

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:background="@drawable/i1"    android:orientation="vertical" >    <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:background="@drawable/ic_dialog_dialer" />        <LinearLayout            android:id="@+id/content"            android:layout_width="fill_parent"            android:layout_height="fill_parent"            android:background="@drawable/default_bg" >            <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>

I. Introduction

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 layout must be set for the controls in the layout file, and handle and content must be specified in the layout file.

For example

<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"> <imagebutton Android: Id = "@ ID/handle" Android: layout_width = "50dip" Android: layout_height = "44dip" Android: src = "@ drawable/Up"/> <linearlayout Android: Id = "@ ID/content" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: Background = "# ffffff"> <textview Android: Id = "@ + ID/TV" Android: layout_width = "match_parent" Android: layout_height = "match_parent" Android: gravity = "center_vertical | center_horizontal" Android: text = "this is an example of a sliding drawer" Android: textcolor = "#000000" Android: textsize = "18px" Android: textstyle = "bold"> </textview> </linearlayout> </sshortingdrawer>

Ii. 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)


Iii. 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): called when slidingdrawer is disabled

Unlock (): unblocks touch events.

Toggle (): Switch the s0000ingdrawer of the opened and closed drawers.


Iv. Complete instance

1. layout file slidingdrawer. xml

<? XML version = "1.0" encoding = "UTF-8"?> <Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: Background = "@ drawable/default_bg" Android: orientation = "vertical"> <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"> <imagebutton Android: id = "@ ID/handle" Android: layout_width = "50dip" Android: layout_height = "44dip" Android: src = "@ drawable/Up"/> <linearlayout Android: id = "@ ID/content" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: Background = "# ffffff"> <textview Android: id = "@ + ID/TV" Android: layout_width = "match_parent" Android: layout_height = "match_parent" Android: gravity = "center_vertical | center_horizontal" Android: TEXT = "this is an example of a sliding drawer" Android: textcolor = "#000000" Android: textsize = "18px" Android: textstyle = "bold"> </textview> </linearlayout> </slidingdrawer> </linearlayout>

2. Java code:

Package COM. way; import android. app. activity; import android. OS. bundle; import android. widget. imagebutton; import android. widget. slidingdrawer; import android. widget. textview; public class sshortingdrawerdemo extends activity {private sshortingdrawer mdrawer; private imagebutton imbg; private Boolean flag = false; private textview TV;/** (non-javadoc) ** @ see android. app. activity # oncreate (Android. OS. bundle) */@ overrideprotected void oncreate (bundle savedinstancestate) {// todo auto-generated method stubsuper. oncreate (savedinstancestate); setcontentview (R. layout. sildingdrawer); imbg = (imagebutton) findviewbyid (R. id. handle); mdrawer = (s0000ingdrawer) findviewbyid (R. id. sshortingdrawer); TV = (textview) findviewbyid (R. id. TV); mdrawer. setondraweropenlistener (New slidingdrawer. ondraweropenlistener () {@ overridepublic void ondraweropened () {flag = true; imbg. setimageresource (R. drawable. down) ;}}); mdrawer. setondrawercloselistener (New s0000ingdrawer. ondrawercloselistener () {@ overridepublic void ondrawerclosed () {flag = false; imbg. setimageresource (R. drawable. up) ;}}); mdrawer. setondrawerscrolllistener (New s0000ingdrawer. ondrawerscrolllistener () {@ overridepublic void onscrollended () {TV. settext ("End dragging") ;}@ overridepublic void onscrollstarted () {TV. settext ("start dragging ");}});}}

 

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.