先看看效果
搞起
依赖
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();
}
});