FlowingMenuLayout,水滴样式抽屉

先看看效果

搞起

依赖 

 implementation 'com.mxn.soul:flowingdrawer-core:2.1.0'
 implementation 'com.nineoldandroids:library:2.4.0'

布局

  <com.mxn.soul.flowingdrawer_core.FlowingDrawer
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/drawerlayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipChildren="false"
        android:clipToPadding="false"
        app:edPosition="1"
        app:edMenuSize="260dp"
        app:edMenuBackground="@color/colorAccent">
        //主界面布局
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <TextView
                android:id="@+id/text1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:textSize="50sp"
                android:text="内容"
                />
            <Button
                android:id="@+id/mBtn1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="打开抽屉"
                />
        </RelativeLayout>
        //抽屉布局
        <com.mxn.soul.flowingdrawer_core.FlowingMenuLayout
            android:id="@+id/menulayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            >
            <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
                <TextView
                    android:id="@+id/text2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:text="抽屉内容"
                    android:textSize="50sp"/>
                <Button
                    android:id="@+id/mBtn2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="关闭抽屉"
                    />
            </LinearLayout>
        </com.mxn.soul.flowingdrawer_core.FlowingMenuLayout>

    </com.mxn.soul.flowingdrawer_core.FlowingDrawer>

主界面布局跟抽屉布局要用一个layout包裹起来

使用

 //初始化 flowingdrawer
        flowingDrawer=findViewById(R.id.drawerlayout);
        //flowingdrawer触摸模式
        flowingDrawer.setTouchMode(ElasticDrawer.TOUCH_MODE_BEZEL);
        //flowingdeawer监听
        flowingDrawer.setOnDrawerStateChangeListener(new ElasticDrawer.OnDrawerStateChangeListener() {
            @Override
            public void onDrawerStateChange(int oldState, int newState) {
                Log.e("onDrawerStateChange","oldState="+oldState+"-----newState"+newState);
            }
            /**
             * openRatio:偏移比例
             * offsetPixels:偏移像素
             * */
            @Override
            public void onDrawerSlide(float openRatio, int offsetPixels) {
                Log.e("onDrawerSlide","openRatio="+openRatio+"-----offsetPixels"+offsetPixels);
                //关闭
                if (openRatio==0){
                text1.setText("已关闭");
                }else{
                    text2.setText("已打开");
                }
            }
        });

        //打开
        mBtn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                flowingDrawer.openMenu();
            }
        });
        //关闭
        mBtn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                flowingDrawer.closeMenu();
            }
        });

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值