1.关于coordinatorLayout与AppBarLayout的文章太多【coordinatorLayout是design包中控件】
简单说就是:当向上滑动内容时AppBarLayout中的内容会隐藏掉,app:layout_behavior="@string/appbar_scrolling_view_behavior"修饰的LinearLayout中的内容会悬浮在顶部,
最下面需要使用recyclerView来加载数据
方法:
appbarlayout.setExpanded(true);//表示展开【会下滑动展开上滑动隐藏的内容】
先看布局代码:
<?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:id="@+id/activity_main2"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbarlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapse_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<include
layout="@layout/layout_activedetail_head"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<CheckBox
android:id="@+id/desc_c"
style="@style/actived_checkbox"
android:layout_marginTop="0dp"
android:text="@string/active_detail" />
</android.support.v4.widget.NestedScrollView>
<android.support.v4.widget.NestedScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone">
<TextView
android:id="@+id/desc_t"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/line_top"
android:padding="10dp"
android:textColor="@color/balck_title"
android:textSize="12sp"
android:visibility="gone" />
</android.support.v4.widget.NestedScrollView>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
>
<CheckBox
android:id="@+id/activesp_t"
style="@style/actived_checkbox"
android:layout_marginTop="0dp"
android:text="@string/active_sp" />
</android.support.v4.widget.NestedScrollView>
<LinearLayout
android:id="@+id/activesp_l"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone">
<android.support.v7.widget.RecyclerView
android:id="@+id/activesp_rv"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="10dp"
>
<CheckBox
android:id="@+id/activefile_c"
style="@style/actived_checkbox"
android:layout_marginTop="0dp"
android:text="@string/active_file" />
</android.support.v4.widget.NestedScrollView>
<LinearLayout
android:id="@+id/activefile_l"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/line_top"
android:visibility="gone">
<android.support.v7.widget.RecyclerView
android:id="@+id/activefile_rv"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
2.LinearLayout中的checkbox本来是没法滑动的,外层添加了NestedScrollView,它就可以控制着整个布局一起上下滑动。具体效果需自己去实践哈。