The openDrawer () and closeDrawer () Methods of DrawerLayout, drawerlayout

Source: Internet
Author: User

The openDrawer () and closeDrawer () Methods of DrawerLayout, drawerlayout

The following code

DrawerLayout mdrawerLayout;

Button btn;

The Declaration component is above, which is omitted in other simple processes.

Btn. setOnClickListener (new OnClickListener (){

MdrawerLayout. openDrawer (Gravity. LEFT); // the direction set here should be the same as the gravity direction in the xml file below. Otherwise, an error will be reported. Both start and LEFT appear from the LEFT.

MdrawerLayout. closDrawers (); // No parameter is set. Close all the drawers that appear.

});

----------------------------------------------------- The following is drawerLayout. xml ----------------------------------------------------------------------

<? Xml version = "1.0" encoding = "UTF-8"?>
<Android. support. v4.widget. DrawerLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: id = "@ + id/dl_left"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent">
<! -- The remaining layout of the main interface is as follows -->
<LinearLayout
Android: layout_width = "match_parent"
Android: layout_height = "match_parent">
<TextView
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "Hello World"/>
</LinearLayout>
<! -- Layout after the drawer is opened, that is, the layout of the ListView -->
<LinearLayout
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: background = "# fff"
Android: orientation = "vertical"
Android: gravity = "center"
Android: layout_gravity = "start">
<ListView
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: id = "@ + id/lv_left_menu"
Android: divider = "@ null">
</ListView>
</LinearLayout>
</Android. support. v4.widget. DrawerLayout>

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.