沉浸式CoordinatorLayout使用小结

版本
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)一次

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值