/
activity_002_collapsing_toolbar_layout.xml
143 lines (123 loc) · 6.25 KB
/
activity_002_collapsing_toolbar_layout.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?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"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_collapseParallaxMultiplier="0.9">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="300dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/ctl"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorAccent"
app:expandedTitleMarginEnd="15dp"
app:expandedTitleMarginStart="15dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<!--
layout_scrollFlags 有如下几种选项:
scroll :想要 CollapsingToolbarLayout 滚出屏幕,必须设置该值,否则 CollapsingToolbarLayout 将被固定在屏幕顶部
exitUntilCollapsed :上滑,折叠在屏幕顶端,继续上滑,CollapsingToolbarLayout 下面的 View 才会退出屏幕;
下滑,CollapsingToolbarLayout 下面的 View 逐渐进入屏幕,继续,CollapsingToolbarLayout 才会展开;
enterAlwaysCollapsed :与 exitUntilCollapsed 类似,但是折叠后不会固定在屏幕顶部;
snap :与 enterAlwaysCollapsed 的最终效果一样,但是没有渐变过程,上滑,逐渐滚出屏幕,中间没有停留,下滑,逐渐中展开,中间没有停留;
enterAlways :上滑,与 enterAlwaysCollapsed 一样的效果,下滑,先展开 CollapsingToolbarLayout,之后其下面的 View 才会进入屏幕;
"scroll|enterAlwaysCollapsed"
"scroll|snap"
"scroll|enterAlways"
"scroll|exitUntilCollapsed"
-->
<!--
contentScrim :折叠后,Toolbar 的背景颜色
-->
<!--
展开时,标题的位置由下面4个属性决定:
app:expandedTitleMarginStart
app:expandedTitleMargin
app:expandedTitleMarginBottom
app:expandedTitleMarginEnd
-->
<ImageView
android:id="@+id/iv_cover"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/ic_launcher_background" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"/>
<!--
app:layout_collapseMode="pin"
Toolbar 的折叠模式,有3种取值:
pin :固定模式,在折叠的时候最后固定在顶端;
parallax :视差模式,在折叠的时候会有个视差折叠的效果;
none :随着滑动滚出屏幕;
-->
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<!--
app:layout_behavior="@string/appbar_scrolling_view_behavior"
通知布局中包含滑动组件,很重要!
-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="15dp">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginBottom="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginBottom="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginBottom="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginBottom="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4" />
</android.support.v7.widget.CardView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:id="@+id/faBtn"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:src="@android:drawable/sym_action_email"
app:layout_anchor="@id/appBar"
app:layout_anchorGravity="bottom|right|end" />
</android.support.design.widget.CoordinatorLayout>