An slidingdrawer class is also called a "drawer" class. It is easy to use, including handle, and content. Handle. When you click it, content is either drawn from the drawer or closed from the drawer. This is the result of pulling the drawer up and down. Set the slidingdrawer attribute to Android: Orientation = "vertical". This is the result of pulling the drawer left and right. Set the slidingdrawer attribute to Android: Orientation = "horizontal.
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.
The layout file in the preceding example:
<? XML version = "1.0" encoding = "UTF-8"?>
<Framelayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: Orientation = "vertical"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">
<Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: Orientation = "vertical"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">
<Textview
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "effect display:"/>
<Slidingdrawer
Android: Id = "@ + ID/drawer1"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: Orientation = "horizontal"
Android: handle = "@ + ID/layout1"
Android: content = "@ + ID/mycontent1">
<Linearlayout
Android: Id = "@ ID/layout1"
Android: Orientation = "vertical"
Android: layout_width = "35sp"
Android: layout_height = "wrap_content"
Android: gravity = "center">
<Imageview
Android: Id = "@ + ID/myimage"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: src = "@ drawable/Open"/>
</Linearlayout>
<Gridview
Android: Id = "@ ID/mycontent1"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: numcolumns = "2"
Android: gravity = "center"/>
</Slidingdrawer>
</Linearlayout>
</Framelayout>
Import Android. App. activity;
Import Android. OS. Bundle;
Import Android. widget. gridview;
Import Android. widget. imageview;
Import Android. widget. slidingdrawer;
Import Android. widget. slidingdrawer. ondrawercloselistener;
Import Android. widget. slidingdrawer. ondraweropenlistener;
Import Android. widget. slidingdrawer. ondrawerscrolllistener;
Public class slidingdraweractivity extends activity {
/** Called when the activity is first created .*/
Private slidingdrawer SD;
Private gridview GV;
Private imageview IV;
Private int [] itemicons = new int [] {
R. drawable. Alarm, R. drawable. calendar,
R. drawable. Camera, R. drawable. Clock,
R. drawable. Music, R. drawable. TV };
Private string [] itemstring = new string [] {"alarm", "calendar", "camera", "Clock", "Music", "TV"}; @ override
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. s0000rawer );
Init ();
Gridadapter adapter = new gridadapter (sjavasingdraweractivity. This, itemstring, itemicons); GV. setadapter (adapter );
/* Set the event processing for the slidingdrawer to be opened */
SD. setondraweropenlistener (New ondraweropenlistener (){
@ Override
Public void ondraweropened (){
// Todo auto-generated method stub
Iv. setimageresource (R. drawable. Close );
}
});
/* Set the event processing when slidingdrawer is disabled */
SD. setondrawercloselistener (New ondrawercloselistener (){
Public void ondrawerclosed (){
Iv. setimageresource (R. drawable. Open );
}
});
SD. setondrawerscrolllistener (New ondrawerscrolllistener (){
@ Override
Public void onscrollstarted (){
// Todo auto-generated method stub
System. Out. println ("START ");
}
@ Override
Public void onscrollended (){
// Todo auto-generated method stub
System. Out. println ("end ");
}
});
}
Private void Init (){
SD = (s0000ingdrawer) findviewbyid (R. Id. drawer1 );
GV = (gridview) findviewbyid (R. Id. mycontent1 );
IV = (imageview) findviewbyid (R. Id. myimage );
}
}
Package com. Shao. Slider;
Import Android. content. context;
Import Android. View. layoutinflater;
Import Android. View. view;
Import Android. View. viewgroup;
Import Android. widget. baseadapter;
Import Android. widget. imageview;
Import Android. widget. textview;
Public class gridadapter extends baseadapter {
Private context;
Private string [] itemstring;
Private int [] itemicons;
Public gridadapter (context con, string [] itemstring, int [] itemicons ){
Context = con;
This. itemstring = itemstring;
This. itemicons = itemicons;
}
@ Override
Public int getcount (){
// Todo auto-generated method stub
Return itemicons. length;
}
@ Override
Public object getitem (INT position ){
// Todo auto-generated method stub
Return itemstring [position];
}
@ Override
Public long getitemid (INT position ){
// Todo auto-generated method stub
Return position;
}
@ Override
Public View getview (INT position, view convertview, viewgroup parent ){
// Todo auto-generated method stub
Layoutinflater Inflater = layoutinflater. From (context );
/* Use item. XML as the layout of each item */
View v = Inflater. Inflate (R. layout. Item, null );
/* Get the view */
Imageview IV = (imageview) v. findviewbyid (R. Id. item_grid );
Textview TV = (textview) v. findviewbyid (R. Id. item_text );
/* Set the displayed image and text? */
Iv. setimageresource (itemicons [position]);
TV. settext (itemstring [position]);
Return V;
}
}
Note that:
S0000ingdrawer shocould be used as an overlay inside layouts. This means s0000ingdrawer shocould only be used inside of a framelayout or a relativelayout for instance. If the display is abnormal, consider the above reasons.