版本
compileSdkVersion 25
buildToolsVersion "25.0.3"
minSdkVersion 14
targetSdkVersion 25
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
CoordinatorLayout是带NestedScrollingParent的FrameLayout
子组件应该是Toolbar(app:layout_scrollFlags="scroll|enterAlways")
+NestedScrollingChild(app:layout_behavior="@string/appbar_scrolling_view_behavior")
app:layout_behavior="@string/appbar_scrolling_view_behavior"
必须加在CoordinatorLayout直接子组件上,否则就是FrameLayout有遮挡
子组件必须是或者包含NestedScrollingChild否则无折叠
子组件内容会超出,对子组件布局应从上往下,底部如果有控件应放外层
当没有app:layout_scrollFlags="scroll|enterAlways"就是LinearLayout有排序不超出
结构例子
<CoordinatorLayout
<AppBarLayout
<CollapsingToolbarLayout
<Toolbar>
CollapsingToolbarLayout>
AppBarLayout>
<Layout
<NestedScrollingChild>
Layout>
CoordinatorLayout>
android:fitsSystemWindows="true"
CoordinatorLayout,AppBarLayout
子组件带有此属性可影响父组件,所以Toolbar写上就好
Toolbar高度设为
android:layout_height="wrap_content"
透明
values-19
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
values-21
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowTranslucentStatus">false</item>
<item name="android:windowTranslucentNavigation">true</item>
DrawerLayout去遮挡
DrawerLayout放最外
android:fitsSystemWindows="false"
外部android:fitsSystemWindows="false"内部true情况下的折叠穿越
动态取一个状态栏高度增加一个View遮挡在CoordinatorLayout外
自定义ListView
NestedListView extends ListView implements NestedScrollingChild
先实现接口再继承ListView,实现直接复制其他原生实现,重写View实现
在代码中需手动调用NestedListView list.setNestedScrollingEnabled(ture)一次