Implementation of Android drawer (s0000ingdrawer)

Source: Internet
Author: User

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>

 

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.