Android control Slidingdrawer (sliding drawer) details and examples

Source: Internet
Author: User

The Slidingdrawer effect must have been seen by everyone, and it is the effect of entering the application list on the 1.5 simulator. Below is

First, Introduction

Slidingdrawer hides content outside the screen and allows users to display hidden content through handle. It can slide vertically or horizontally, it has two view components, one is the handle that can be dragged, the other is the view of the hidden content. The controls inside it must be laid out, and handle and content must be specified in the layout file.

For example, below

<slidingdrawer android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent" android:handle= "@+id/handle"
Android:content= "@+id/content" android:orientation= "vertical"
Android:id= "@+id/slidingdrawer" >

<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:text= "This is an example of a sliding drawer"
Android:id= "@+id/tv"
Android:textsize= "18px"
Android:textcolor= "#000000"
Android:gravity= "Center_vertical|center_horizontal"
Android:layout_width= "Match_parent"
Android:textstyle= "Bold"
android:layout_height= "Match_parent" ></TextView>
</LinearLayout>

</SlidingDrawer>

Second, important attributes

Android:allowsingletap: Indicates whether the handle can be turned on or off via the

Android:animateonclick: Indicates whether there is an animation when the consumer presses the handle to open/close.

Android:content: Hidden content

Android:handle:handle (handle)

Iii. Important methods

  Animateclose (): animations are implemented when off.

  Close (): Instant off

  GetContent (): Get content

  Ismoving (): Indicates whether the slidingdrawer is moving.

  Isopened (): Indicates whether Slidingdrawer is all open

  Lock (): Mask Touch event.

  Setondrawercloselistener (Slidingdrawer.ondrawercloselistener Ondrawercloselistener): Called when SlidingDrawer is closed

  Unlock (): Unblock touch event.

  Toggle (): Toggles the open and closed drawer slidingdrawer.

Iv. Complete Examples

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:orientation= "vertical" android:background= "@drawable/default_bg" >

<slidingdrawer android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent" android:handle= "@+id/handle"
Android:content= "@+id/content" android:orientation= "vertical"
Android:id= "@+id/slidingdrawer" >

<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:text= "This is an example of a sliding drawer"
Android:id= "@+id/tv"
Android:textsize= "18px"
Android:textcolor= "#000000"
Android:gravity= "Center_vertical|center_horizontal"
Android:layout_width= "Match_parent"
Android:textstyle= "Bold"
android:layout_height= "Match_parent" ></TextView>
</LinearLayout>

</SlidingDrawer>
</LinearLayout>

2.Java Code

Package COM.WJQ;

Import android.app.Activity;
Import Android.os.Bundle;
Import Android.widget.ImageButton;
Import Android.widget.SlidingDrawer;
Import Android.widget.TextView;

public class Slidingdrawerdemo extends Activity {
Private Slidingdrawer Mdrawer;
Private ImageButton IMBG;
Private Boolean Flag=false;
Private TextView TV;
/* (Non-javadoc)
* @see Android.app.activity#oncreate (android.os.Bundle)
*/
@Override
protected void OnCreate (Bundle savedinstancestate) {
TODO auto-generated Method Stub
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.sildingdrawer);

Imbg= (ImageButton) Findviewbyid (R.id.handle);
Mdrawer= (Slidingdrawer) Findviewbyid (r.id.slidingdrawer);
tv= (TextView) Findviewbyid (r.id.tv);

Mdrawer.setondraweropenlistener (New Slidingdrawer.ondraweropenlistener ()
{
@Override
public void ondraweropened () {
Flag=true;
Imbg.setimageresource (R.drawable.down);
}

});

Mdrawer.setondrawercloselistener (New Slidingdrawer.ondrawercloselistener () {

@Override
public void ondrawerclosed () {
Flag=false;
Imbg.setimageresource (r.drawable.up);
}

});

Mdrawer.setondrawerscrolllistener (New Slidingdrawer.ondrawerscrolllistener () {

@Override
public void onscrollended () {
Tv.settext ("End Drag");
}

@Override
public void onscrollstarted () {
Tv.settext ("Start dragging");
}

});


}

}

Http://www.cnblogs.com/salam/archive/2010/10/19/1855511.html

Android control Slidingdrawer (sliding drawer) details and examples

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.