<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--见下面1.1-->
<include layout="@layout/toolbar_main"/>
<!--见下面1.2-->n
<include layout="@layout/nestedScrollView"/>
</android.support.design.widget.CoordinatorLayout>
1.1
<android.support.design.widget.AppBarLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/AppBarLayout01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp">
<!--必要嵌套在appbarlayout中,等于帮我们实现的默认的behaviour-->
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
/>
<!--需要写scrollflags,有scroll就行-->
</android.support.design.widget.AppBarLayout>
ScrollFlags共有五种常量值供AppBarLayout的Children View使用,在xml布局文件中通过app:layout_scrollFlags设置,对应的值为:scroll,enterAlways,enterAlwaysCollapsed,snap,exitUntilCollapsed;也可以在代码中通过setScrollFlags(int)方法使用,比如:
Toolbar toolbar = ... // your toolbar within an AppBarLayout
AppBarLayout.LayoutParams params =
(AppBarLayout.LayoutParams) toolbar.getLayoutParams();
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL
| AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
各个属性详情见:https://www.jianshu.com/p/7caa5f4f49bd
1.2
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/Blue"
app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior">
<!--需要带有系统自带的behavior-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
layout="@layout/container"
android:visibility="visible" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
网友评论