Side Sliding Menu DrawerLayout

Matters needing attention:
1. It is best for DrawerLayout to be == the root layout of the interface==, otherwise there may be a problem that touch events are blocked
2. The layout code of the main content area should be placed in front of the side sliding menu layout—== planning menu Must put last ==
3. == The layout of the side slide menu part (here is ListView) must set the layout_gravity property ==

界面的根布局
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.mydrawerlayout.MainActivity">
DrawerLayout.DrawerListener的实时监听 :
drawer.setDrawerListener(new DrawerLayout.DrawerListener() {
            //当侧拉栏滑动的时候调用此方法
            @Override
            public void onDrawerSlide(View drawerView, float slideOffset) {
            }
            //当侧拉栏打开的时候调用此方法
            @Override
            public void onDrawerOpened(View drawerView) {
            }
            //当侧拉栏关闭的时候调用此方法
            @Override
            public void onDrawerClosed(View drawerView) {

            }
            /**当抽屉滑动状态改变的时候被调用
             * 状态值是STATE_IDLE(闲置--0), STATE_DRAGGING(拖拽的--1), STATE_SETTLING(固定--2)中之一。
             * 抽屉打开的时候,点击抽屉,drawer的状态就会变成STATE_DRAGGING,然后变成STATE_IDLE*/
            @Override
            public void onDrawerStateChanged(int newState) {

            }
        });

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325392347&siteId=291194637