DrawLayout的简单使用

      侧滑菜单的实现,本博客知道的就两种,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">
            <FrameLayout
android: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();
这里面可以监听到侧滑的开始和结束还有侧滑时的状态





介绍结束
 



















  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值