Android s0000ingdrawer (slide drawer)

Source: Internet
Author: User

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.
You may have seen the SlidingDrawer effect, which is the effect of entering the Application List on the 1.5 simulator. Below is
Details and examples of Android s0000ingdrawer (slide drawer)

 
  
 
 
Details and examples of Android s0000ingdrawer (slide drawer)
 
 
For example
<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 slide 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>
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 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: 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 slide 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 s0000ingdrawer. 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 dragging ");
}
@ Override
Public void onScrollStarted (){
TV. setText ("start dragging ");
}
});
}
}
Author: t80t90s

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.