Implementation of Android Drawer

Source: Internet
Author: User

Implementation of Android Drawer

A drawer control required in Android. The following is a simple implementation process.

First, write a layout. The layout should be noted as follows:

1. It must be the drawerLayou layout.

Android. support. v4.widget. DrawerLayout 2. There can only be two large layout s in drawerLayout 3. You must define whether the closed drawer is left or right.

 

 

     
 
          
   
    
Android: layout_gravity = right android: background = # ffffff>
   
  
 

 

The specific code implementation is as follows:

 

Public class MainActivity extends Activity implements OnClickListener {private Button button_Open, button_Close; private RelativeLayout relative_Close; private DrawerLayout drawerLayout; protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); initUI ();} private void initUI () {button_Open = (Button) findViewById (R. id. button_open); button_Open.setOnClickListener (this); button_Close = (Button) findViewById (R. id. button_close); button_Close.setOnClickListener (this); relative_Close = (RelativeLayout) findViewById (R. id. relative_close); // set the size of the closed drawer LayoutParams layoutParams = relative_Close.getLayoutParams (); Display play = getWindowManager (). getdefadisplay display (); layoutParams. width = play. getWidth () * 4/5; relative_Close.setLayoutParams (layoutParams); drawerLayout = (DrawerLayout) findViewById (R. id. drawer) ;}@ Overridepublic void onClick (View v) {switch (v. getId () {case R. id. button_open: // open the drawer drawerLayout. openDrawer (relative_Close); break; case R. id. button_close: // close the drawer drawerLayout. closeDrawer (relative_Close); break ;}}}
 

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.