DrawLayout的简单使用

来源:互联网 发布:java分支语句行李 编辑:程序博客网 时间:2024/06/05 08:18

      侧滑菜单的实现,本博客知道的就两种,slidingMenu和DrawLayout两种,这一篇为大家介绍一下android自带的侧滑菜单drawLayout,drawLayout使用起来非常方便,主要是xml布局中实现,下面是布局

 drawLayout就是把要侧滑的布局全部放在

android.support.v4.widget.DrawerLayout的布局内,固定在中间的使用属性
android:gravity="center"从左边侧滑的布局需要设置的属性是:
 android:layout_gravity="left"
从右边侧滑的布局需要设置的属性是:
 android:layout_gravity="right"
如果这些属性没有提示,不要认为错误,手动打出这些属性



 <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"        android:id="@+id/dlMenu"        android:layout_width="match_parent"        android:layout_height="match_parent"        tools:layout_editor_absoluteY="8dp"        tools:layout_editor_absoluteX="8dp">    <LinearLayout            android:orientation="vertical"            android:layout_width="match_parent"            android:layout_height="match_parent"            android:gravity="center"            >        <LinearLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:orientation="horizontal"            android:gravity="center_vertical"            >                              <android.support.v4.view.ViewPager                android:layout_width="match_parent"                android:layout_height="match_parent"                android:id="@+id/vp_main"                >            </android.support.v4.view.ViewPager>                <LinearLayout            android:id="@+id/left_sliding"            android:layout_gravity="left"            android:layout_width="match_parent"            android:layout_height="match_parent">            <FrameLayoutandroid:id="@+id/fl_left"                android:layout_width="match_parent"                android:layout_height="match_parent">            </FrameLayout>        </LinearLayout> <LinearLayout            android:id="@+id/right_sliding"            android:layout_gravity="right"            android:layout_width="match_parent"            android:layout_height="match_parent">            <FrameLayout                 android:id="@+id/fl_right"                android:layout_width="match_parent"                android:layout_height="match_parent">            </FrameLayout>  </LinearLayout>    </android.support.v4.widget.DrawerLayout>在activity中的调用控件
DrawLayout drawerLayout = (DrawerLayout) findViewById(R.id.dlMenu);最后为大家介绍常用的方法drawerLayout.openDrawer(ll_left);//打开左侧滑
drawerLayout.openDrawer(ll_right);//打开右侧滑
drawerLayout.closeDrawer(ll_left);//关闭左侧滑
drawerLayout.closeDrawer(ll_right);//关闭右侧滑
drawerLayout.closeDrawers();//关闭所有侧滑

判断是否打开
drawerLayout.isDrawerOpen(ll_right);//判断右边是否打开
drawerLayout.isDrawerOpen(ll_left);//判断左边是否打开//监听
drawerLayout.addDrawerListener();这里面可以监听到侧滑的开始和结束还有侧滑时的状态介绍结束
 



















原创粉丝点击