Slidingdrawer effect must have been seen, it is the 1.5 simulator to enter the application list effect. Here's a screenshot.
First, Introduction
Slidingdrawer hides the content outside the screen and allows the user to handle to display hidden content. It can slide vertically or horizontally, it has two view components, one is the handle that can be dragged, and the other is the view of the hidden content. The controls inside it must be laid out and the handle and content must be specified in the layout file.
such as the following
Copy Code code as follows:
<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 can be turned on or off by handle
Android:animateonclick: Indicates whether there should be an animation when the consumer presses the handle on/off.
Android:content: Hidden content
Android:handle:handle (handle)
Iii. Important methods
Animateclose (): Animations are implemented when closed.
Close (): Immediate shutdown
GetContent (): Getting content
Ismoving (): Indicates whether the slidingdrawer is moving.
Isopened (): Indicates whether Slidingdrawer is all open
Lock (): Masks Touch events.
Setondrawercloselistener (Slidingdrawer.ondrawercloselistener Ondrawercloselistener): Called when SlidingDrawer shutdown
Unlock (): Unblock touch event.
Toggle (): Toggle open and close drawer slidingdrawer.
Four, complete example
1. layout file Slidingdrawer.xml
Copy Code code as follows:
<?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
Copy Code code as follows:
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");
}
});
}
}