MainActivity is as follows:
Package c. c; import android. app. activity; import android. OS. bundle; import android. widget. slidingDrawer; import android. widget. slidingDrawer. onDrawerCloseListener; import android. widget. slidingDrawer. onDrawerOpenListener; import android. widget. slidingDrawer. onDrawerScrollListener;/*** Requirement Description: * implement a simple drawer Demo * Note: * 1 open the drawer icon, the displayed interface is displayed in <SlidingDrawer/> * 2 in <SlidingDrawer/> * use: android: handle = "@ + id/handle_layout" * used to specify the drawer handle *: android: content = "@ + id/content_layout" * specifies the View * 3 s0000ingdrawer after opening the drawer. A total of three listening events (see the code) * Note the execution sequence of the three events. The general principle is: * After sliding, open (or close) the drawer * So: execution sequence * // 1 Optional * // 2 setOnDrawerOpenListener * or optional */public class MainActivity extends Activity {private s0000ingdrawer ms0000ingdrawer; @ Override public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. main); init () ;}// execution sequence // 1 setOnDrawerScrollListener // 2 setOnDrawerOpenListener (or listener) private void init () {mSlidingDrawer = (SlidingDrawer) findViewById (R. id. slidingDrawer); mSlidingDrawer. setOnDrawerScrollListener (new OnDrawerScrollListener () {public void onScrollStarted () {System. out. println ("--------> start sliding");} public void onScrollEnded () {System. out. println ("--------> sliding end") ;}}); mSlidingDrawer. setOnDrawerOpenListener (new OnDrawerOpenListener () {public void onDrawerOpened () {System. out. println ("--------> open drawer") ;}}); mSlidingDrawer. setOnDrawerCloseListener (new OnDrawerCloseListener () {public void onDrawerClosed () {System. out. println ("--------> close drawer ");}});}}
Main. xml is as follows:
<RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android" xmlns: tools = "http://schemas.android.com/tools" android: layout_width = "match_parent" android: layout_height = "match_parent"> <TextView android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_alignParentTop = "true" android: layout_centerHorizontal = "true" android: text = "test drawer effect"/> <SlidingDrawer android: id = "@ + id/slidingDrawer" android: layout_width = "fill_parent" android: layout_height = "fill_parent" android: handle = "@ + id/handle_layout" android: content = "@ + id/content_layout" android: orientation = "horizontal"> <LinearLayout android: id = "@ + id/handle_layout" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: orientation = "horizontal"> <ImageView android: id = "@ + id/imageView" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: src = "@ drawable/ic_launcher"/> </LinearLayout> <LinearLayout android: id = "@ + id/content_layout" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: orientation = "horizontal"> <Button android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "Button1"/> <Button android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "Button2"/> <Button android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "Button3"/> </LinearLayout> </SlidingDrawer> </RelativeLayout>