常见的是 CoordinatorLayout + appbarlayout + toolbar(悬停) + viewPager(recycleview)这种状态
但是如果添加上抽屉的话,会导致手势冲突
1、toolbar无法悬停(需要套一层coordinatorLayout)
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="false"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
style="@style/MainAppBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
style="@style/MainToolbarStyle"
android:layout_width="match_parent"
app:layout_scrollFlags="enterAlways|snap" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
style="@style/MainTabLayoutStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="enterAlways|snap" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="?attr/actionBarSize"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<!-- Bottom Sheet -->
<LinearLayout
android:id="@+id/ll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorBackgroundFloating"
android:elevation="16dp"
android:orientation="vertical"
app:behavior_peekHeight="155dp"
app:layout_behavior="@string/view_pager_bottom_sheet_behavior">
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#ff00ff" />
<android.support.design.widget.CoordinatorLayout
android:id="@+id/cl"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/bottom_sheet_appbar"
style="@style/BottomSheetAppBarStyle"
app:layout_behavior=".CustomBehavior"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
app:layout_scrollFlags="scroll|enterAlwaysCollapsed"
android:id="@+id/tv"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#00ff00"
/>
<android.support.design.widget.TabLayout
android:id="@+id/bottom_sheet_tabs"
style="@style/BottomSheetTabLayoutStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/bottom_sheet_viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
2、toolbar悬停半截时候 下拉无法打开toolbar 抽屉直接下拉(监听appbarLayout 的 AppBarLayout.OnOffsetChangedListener 判断是否折叠 、打开、中间状态 )
al.addOnOffsetChangedListener(new AppBarStateChangeListener() {
@Override
public void onStateChanged(AppBarLayout appBarLayout, State state) {
if( state == State.EXPANDED ) {
Log.e("展开状态","---");
//展开状态
from.isFlod(true);
}else if(state == State.COLLAPSED){
Log.e("折叠状态","---");
from.isFlod(false);
//折叠状态
}else {
from.isFlod(false);
Log.e("中间状态","---");
//中间状态
}
}
});
参考文章
https://www.jianshu.com/p/9b5e1cf6f755
https://blog.csdn.net/wjw_java_android/article/details/107207977
代码下载连接
https://download.csdn.net/download/androidwubo/16681592?spm=1001.2014.3001.5503