Android实用技术: CoordinatorLayout使用详解

时间:2022-04-16 06:25:46

Android实用技术: CoordinatorLayout使用详解


注:本文转自:http://blog.csdn.net/xyz_lmn/article/details/48055919,仅作学习交流。


一、CoordinatorLayo有什么作用


CodinatorLayout作为“super-powered FrameLayout”基本实现两个功能: 
1、作为顶层布局 
2、调度协调子布局


CoordinatorLayout使用新的思路通过协调调度子布局的形式实现触摸影响布局的形式产生动画效果。CoordinatorLayout通过设置子View的 Behaviors来调度子View。系统(Support V7)提供了AppBarLayout.Behavior, AppBarLayout.ScrollingViewBehavior, FloatingActionButton.Behavior, SwipeDismissBehavior<V extends View> 等。

使用CoordinatorLayout需要在Gradle加入Support Design Library:


<code class="language-java hljs  has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span style="font-size:14px;">compile <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'com.android.support:design:22.2.1'</span></span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">1</span></li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">1</span></li></ul>


二、CoordinatorLayout与FloatingActionButton

定义布局文件:

<code class="language-xml hljs  has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span style="font-size:14px;"><span class="hljs-pi" style="color: rgb(0, 102, 102); box-sizing: border-box;"><?xml version="1.0" encoding="utf-8"?></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">android.support.design.widget.CoordinatorLayout
</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">xmlns:android</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"http://schemas.android.com/apk/res/android"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">xmlns:app</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"http://schemas.android.com/apk/res-auto"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_width</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"match_parent"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_height</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"match_parent"</span>></span>


<span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">android.support.design.widget.FloatingActionButton
</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:id</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"@+id/fab"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_width</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"wrap_content"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_height</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"wrap_content"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_gravity</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"end|bottom"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_margin</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"16dp"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:src</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"@drawable/ic_done"</span> /></span>

<span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"></<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">android.support.design.widget.CoordinatorLayout</span>></span></span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">1</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">2</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">3</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">4</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">5</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">6</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">7</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">8</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">9</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">10</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">11</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">12</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">13</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">14</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">15</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">16</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">17</span></li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">1</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">2</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">3</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">4</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">5</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">6</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">7</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">8</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">9</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">10</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">11</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">12</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">13</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">14</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">15</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">16</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">17</span></li></ul>

CoordinatorLayout作为“super-powered FrameLayout”,设置子视图的Android:layout_gravity属性控制位置。

Activity:

<code class="language-java hljs  has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span style="font-size:14px;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">public</span> <span class="hljs-class" style="box-sizing: border-box;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">class</span> <span class="hljs-title" style="box-sizing: border-box; color: rgb(102, 0, 102);">MainActivity</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">extends</span> <span class="hljs-title" style="box-sizing: border-box; color: rgb(102, 0, 102);">AppCompatActivity</span> {</span>

<span class="hljs-annotation" style="color: rgb(155, 133, 157); box-sizing: border-box;">@Override</span>
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">protected</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">void</span> <span class="hljs-title" style="box-sizing: border-box;">onCreate</span>(Bundle savedInstanceState) {
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">super</span>.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.fab).setOnClickListener(<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">new</span> View.OnClickListener() {
<span class="hljs-annotation" style="color: rgb(155, 133, 157); box-sizing: border-box;">@Override</span>
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">public</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">void</span> <span class="hljs-title" style="box-sizing: border-box;">onClick</span>(View view) {

Snackbar.make(view,<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"FAB"</span>,Snackbar.LENGTH_LONG)
.setAction(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"cancel"</span>, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">new</span> View.OnClickListener() {
<span class="hljs-annotation" style="color: rgb(155, 133, 157); box-sizing: border-box;">@Override</span>
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">public</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">void</span> <span class="hljs-title" style="box-sizing: border-box;">onClick</span>(View v) {
<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//这里的单击事件代表点击消除Action后的响应事件</span>

}
})
.show();
}
});
}
}</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">1</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">2</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">3</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">4</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">5</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">6</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">7</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">8</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">9</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">10</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">11</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">12</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">13</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">14</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">15</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">16</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">17</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">18</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">19</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">20</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">21</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">22</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">23</span></li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">1</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">2</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">3</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">4</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">5</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">6</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">7</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">8</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">9</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">10</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">11</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">12</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">13</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">14</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">15</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">16</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">17</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">18</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">19</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">20</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">21</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">22</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">23</span></li></ul>

效果: 
Android实用技术: CoordinatorLayout使用详解

FloatingActionButton是最简单的使用CoordinatorLayout的例子,FloatingActionButton默认使用FloatingActionButton.Behavior。


三、CoordinatorLayout与AppBarLayout

       3.1 AppBarLayout嵌套TabLayout

布局文件代码:

<code class="language-xml hljs  has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span style="font-size:14px;">
<span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">android.support.design.widget.CoordinatorLayout</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">xmlns:android</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"http://schemas.android.com/apk/res/android"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">xmlns:app</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"http://schemas.android.com/apk/res-auto"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:id</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"@+id/main_content"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_width</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"match_parent"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_height</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"match_parent"</span>></span>

<span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">android.support.design.widget.AppBarLayout
</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:id</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"@+id/appbar"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_width</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"match_parent"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_height</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"wrap_content"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:theme</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"@style/ThemeOverlay.AppCompat.Dark.ActionBar"</span>></span>

<span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">android.support.v7.widget.Toolbar
</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:id</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"@+id/toolbar"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_width</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"match_parent"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_height</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"?attr/actionBarSize"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:background</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"?attr/colorPrimary"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">app:popupTheme</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"@style/ThemeOverlay.AppCompat.Light"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">app:layout_scrollFlags</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"scroll|enterAlways"</span> /></span>

<span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">android.support.design.widget.TabLayout
</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:id</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"@+id/tabs"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_width</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"match_parent"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_height</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"wrap_content"</span> /></span>

<span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"></<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">android.support.design.widget.AppBarLayout</span>></span>

<span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">android.support.v4.view.ViewPager
</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:id</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"@+id/viewpager"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_width</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"match_parent"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_height</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"match_parent"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">app:layout_behavior</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"@string/appbar_scrolling_view_behavior"</span> /></span>

<span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">android.support.design.widget.FloatingActionButton
</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:id</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"@+id/fab"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_width</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"wrap_content"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_height</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"wrap_content"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_gravity</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"end|bottom"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_margin</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"@dimen/fab_margin"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:src</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"@drawable/ic_done"</span> /></span>

<span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"></<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">android.support.design.widget.CoordinatorLayout</span>></span></span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">1</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">2</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">3</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">4</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">5</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">6</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">7</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">8</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">9</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">10</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">11</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">12</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">13</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">14</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">15</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">16</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">17</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">18</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">19</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">20</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">21</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">22</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">23</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">24</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">25</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">26</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">27</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">28</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">29</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">30</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">31</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">32</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">33</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">34</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">35</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">36</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">37</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">38</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">39</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">40</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">41</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">42</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">43</span></li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">1</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">2</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">3</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">4</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">5</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">6</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">7</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">8</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">9</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">10</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">11</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">12</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">13</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">14</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">15</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">16</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">17</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">18</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">19</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">20</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">21</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">22</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">23</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">24</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">25</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">26</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">27</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">28</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">29</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">30</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">31</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">32</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">33</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">34</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">35</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">36</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">37</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">38</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">39</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">40</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">41</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">42</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">43</span></li></ul>

效果: 
Android实用技术: CoordinatorLayout使用详解


效果显示,视图滚动时,Toolbar会隐藏,这个效果是Android Support Library里面,新增的CoordinatorLayout, AppBarLayout实现的。通过AppBarLayout的子视图的属性控制。观察AppBarLayout的子布局,Toobar有app:layout_scrollFlags属性,这就是控制滑动时视图效果的属性。app:layout_scrollFlags有四个值:
  1. scroll: 所有想滚动出屏幕的view都需要设置这个flag, 没有设置这个flag的view将被固定在屏幕顶部。例如,TabLayout 没有设置这个值,将会停留在屏幕顶部。
  2. enterAlways: 设置这个flag时,向下的滚动都会导致该view变为可见,启用快速“返回模式”。
  3. enterAlwaysCollapsed: 当你的视图已经设置minHeight属性又使用此标志时,你的视图只能已最小高度进入,只有当滚动视图到达顶部时才扩大到完整高度。
  4. exitUntilCollapsed: 滚动退出屏幕,最后折叠在顶端。


为了ToolBar可以滚动,CoordinatorLayout里面,放一个带有可滚动的View.如上的例子,放的是ViewPager,而ViewPager里面是放了RecylerView的,即是可以滚动的View。CoordinatorLayout包含的子视图中带有滚动属性的View需要设置app:layout_behavior属性。例如,示例中Viewpager设置了此属性。


<code class="language-xml hljs  has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span style="font-size:14px;">app:layout_behavior="@string/appbar_scrolling_view_behavior"</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">1</span></li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">1</span></li></ul>

为了使得Toolbar有滑动效果,必须做到如下三点: 
1. CoordinatorLayout作为布局的父布局容器。 
2. 给需要滑动的组件设置 app:layout_scrollFlags=”scroll|enterAlways” 属性。 
3. 给滑动的组件设置app:layout_behavior属性



3.2 AppBarLayout嵌套CollapsingToolbarLayout

<code class="language-xml hljs  has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span style="font-size:14px;"><span class="hljs-pi" style="color: rgb(0, 102, 102); box-sizing: border-box;"><?xml version="1.0" encoding="utf-8"?></span>
<span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">android.support.design.widget.CoordinatorLayout</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">xmlns:android</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"http://schemas.android.com/apk/res/android"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">xmlns:app</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"http://schemas.android.com/apk/res-auto"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:id</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"@+id/main_content"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_width</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"match_parent"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_height</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"match_parent"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:fitsSystemWindows</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"true"</span>></span>

<span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">android.support.design.widget.AppBarLayout
</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:id</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"@+id/appbar"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_width</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"match_parent"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_height</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"256dp"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:theme</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"@style/ThemeOverlay.AppCompat.Dark.ActionBar"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:fitsSystemWindows</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"true"</span>></span>

<span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">android.support.design.widget.CollapsingToolbarLayout
</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:id</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"@+id/collapsing_toolbar"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_width</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"match_parent"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_height</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"match_parent"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">app:layout_scrollFlags</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"scroll|exitUntilCollapsed"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:fitsSystemWindows</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"true"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">app:contentScrim</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"?attr/colorPrimary"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">app:expandedTitleMarginStart</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"48dp"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">app:expandedTitleMarginEnd</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"64dp"</span>></span>

<span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">ImageView
</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:id</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"@+id/backdrop"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_width</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"match_parent"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_height</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"match_parent"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:scaleType</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"centerCrop"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:fitsSystemWindows</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"true"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:src</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"@drawable/header"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">app:layout_collapseMode</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"parallax"</span>
/></span>

<span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">android.support.v7.widget.Toolbar
</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:id</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"@+id/toolbar"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_width</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"match_parent"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_height</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"?attr/actionBarSize"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">app:popupTheme</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"@style/ThemeOverlay.AppCompat.Light"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">app:layout_collapseMode</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"pin"</span> /></span>

<span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"></<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">android.support.design.widget.CollapsingToolbarLayout</span>></span>

<span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"></<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">android.support.design.widget.AppBarLayout</span>></span>

<span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">android.support.v4.widget.NestedScrollView
</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_width</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"match_parent"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_height</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"match_parent"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">app:layout_behavior</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"@string/appbar_scrolling_view_behavior"</span>></span>

<span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">LinearLayout
</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_width</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"match_parent"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_height</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"match_parent"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:orientation</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"vertical"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:paddingTop</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"24dp"</span>></span>

<span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">android.support.v7.widget.CardView
</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_width</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"match_parent"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_height</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"wrap_content"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_margin</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"16dp"</span>></span>

<span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">LinearLayout
</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">style</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"@style/Widget.CardContent"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_width</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"match_parent"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_height</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"wrap_content"</span>></span>

<span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">TextView
</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_width</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"match_parent"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_height</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"wrap_content"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:text</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"CardView"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:textAppearance</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"@style/TextAppearance.AppCompat.Title"</span> /></span>

<span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">TextView
</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_width</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"match_parent"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_height</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"wrap_content"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:text</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"@string/card_string"</span> /></span>

<span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"></<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">LinearLayout</span>></span>

<span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"></<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">android.support.v7.widget.CardView</span>></span>
……
<span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"></<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">LinearLayout</span>></span>

<span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"></<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">android.support.v4.widget.NestedScrollView</span>></span>

<span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">android.support.design.widget.FloatingActionButton
</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_height</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"wrap_content"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_width</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"wrap_content"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">app:layout_anchor</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"@id/appbar"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">app:layout_anchorGravity</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"bottom|right|end"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:src</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"@drawable/ic_done"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_margin</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"@dimen/fab_margin"</span>
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:clickable</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"true"</span>/></span>

<span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"></<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">android.support.design.widget.CoordinatorLayout</span>></span>
</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">1</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">2</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">3</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">4</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">5</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">6</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">7</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">8</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">9</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">10</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">11</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">12</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">13</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">14</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">15</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">16</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">17</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">18</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">19</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">20</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">21</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">22</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">23</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">24</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">25</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">26</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">27</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">28</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">29</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">30</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">31</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">32</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">33</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">34</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">35</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">36</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">37</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">38</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">39</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">40</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">41</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">42</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">43</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">44</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">45</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">46</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">47</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">48</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">49</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">50</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">51</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">52</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">53</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">54</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">55</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">56</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">57</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">58</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">59</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">60</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">61</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">62</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">63</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">64</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">65</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">66</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">67</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">68</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">69</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">70</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">71</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">72</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">73</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">74</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">75</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">76</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">77</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">78</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">79</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">80</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">81</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">82</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">83</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">84</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">85</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">86</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">87</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">88</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">89</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">90</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">91</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">92</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">93</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">94</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">95</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">96</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">97</span></li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">1</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">2</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">3</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">4</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">5</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">6</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">7</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">8</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">9</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">10</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">11</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">12</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">13</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">14</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">15</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">16</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">17</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">18</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">19</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">20</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">21</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">22</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">23</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">24</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">25</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">26</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">27</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">28</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">29</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">30</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">31</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">32</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">33</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">34</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">35</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">36</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">37</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">38</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">39</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">40</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">41</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">42</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">43</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">44</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">45</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">46</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">47</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">48</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">49</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">50</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">51</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">52</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">53</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">54</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">55</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">56</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">57</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">58</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">59</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">60</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">61</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">62</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">63</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">64</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">65</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">66</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">67</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">68</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">69</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">70</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">71</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">72</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">73</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">74</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">75</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">76</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">77</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">78</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">79</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">80</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">81</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">82</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">83</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">84</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">85</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">86</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">87</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">88</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">89</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">90</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">91</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">92</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">93</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">94</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">95</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">96</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">97</span></li></ul>

效果: 
Android实用技术: CoordinatorLayout使用详解


        这种效果在详情页面用的较多,展示个性化内容,图像有强烈的吸引力。这个效果重点使用了CollapsingToolbarLayout 。 
CollapsingToolbarLayout可实现Toolbar的折叠效果。CollapsingToolbarLayout的子视图类似与LinearLayout垂直方向排放。

       CollapsingToolbarLayout 提供以下属性和方法是用: 
                1. Collapsing title:ToolBar的标题,当CollapsingToolbarLayout全屏没有折叠时,title显示的是大字体,在折叠的过程中,title不断变小到一定大小的效果。你可以调用setTitle(CharSequence)方法设置title。 
                2. Content scrim:ToolBar被折叠到顶部固定时候的背景,你可以调用setContentScrim(Drawable)方法改变背景或者 在属性中使用 app:contentScrim=”?attr/colorPrimary”来改变背景。 
                3. Status bar scrim:状态栏的背景,调用方法setStatusBarScrim(Drawable)。还没研究明白,不过这个只能在Android5.0以上系统有效果。 
                4. Parallax scrolling children:CollapsingToolbarLayout滑动时,子视图的视觉差,可以通过属性app:layout_collapseParallaxMultiplier=”0.6”改变。值de的范围[0.0,1.0],值越大视察越大。 
                5. CollapseMode :子视图的折叠模式,在子视图设置,有两种“pin”:固定模式,在折叠的时候最后固定在顶端;“parallax”:视差模式,在折叠的时候会有个视差折叠的效果。我们可以在布局中使用属性
app:layout_collapseMode=”parallax”来改变。

        CoordinatorLayout 还提供了一个 layout_anchor 的属性,连同 layout_anchorGravity 一起,可以用来放置与其他视图关联在一起的悬浮视图(如 FloatingActionButton)。本例中使用FloatingActionButton。

        通过下面的参数设置了FloatingActionButton的位置,两个属性共同作用使得FAB 浮动按钮也能折叠消失,展现。

<code class="language-xml hljs  has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span style="font-size:14px;">app:layout_anchor="@id/appbar"
app:layout_anchorGravity="bottom|right|end"</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">1</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">2</span></li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">1</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">2</span></li></ul>

使用CollapsingToolbarLayout实现折叠效果,需要注意3点 
1. AppBarLayout的高度固定 
2. CollapsingToolbarLayout的子视图设置layout_collapseMode属性 
3. 关联悬浮视图设置app:layout_anchor,app:layout_anchorGravity属性

四、自定义behavior

CoordinatorLayout功能如此强大,而他的神奇之处在于Behavior对象,CoordinatorLayout自己并不控制View,所有的控制权都在Behavior。前面写到了FloatingActionButton.Behavior,AppBarLayout.Behavior, AppBarLayout.ScrollingViewBehavior。 AppBarLayout中有两个Behavior,一个是拿来给它自己用的,另一个是拿来给它的兄弟结点用的。这些Behavior实现了复杂的控制功能。系统的Behavior毕竟有限,我们可以通过自定义的方式来实现自己的Behavior。

        通过 CoordinatorLayout.Behavior(YourView.Behavior.class) 来定义自己的Behavior,并在layout 文件中设置 app:layout_behavior=”com.example.app.YourView$Behavior” 来达到效果。

自定义Behavior 需要重写两个方法:

<code class="language-java hljs  has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span style="font-size:14px;"> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">public</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">boolean</span> <span class="hljs-title" style="box-sizing: border-box;">layoutDependsOn</span>(CoordinatorLayout parent, View child, View dependency) 

<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">public</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">boolean</span> <span class="hljs-title" style="box-sizing: border-box;">onDependentViewChanged</span>(CoordinatorLayout parent, View child, View dependency)</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">1</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">2</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">3</span></li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">1</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">2</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">3</span></li></ul>

如下面的例子,实现了点击FloatingActionButton点击旋转90度,并适配Snackbar。

<code class="language-java hljs  has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span style="font-size:14px;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">public</span> <span class="hljs-class" style="box-sizing: border-box;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">class</span> <span class="hljs-title" style="box-sizing: border-box; color: rgb(102, 0, 102);">RotateBehavior</span>  <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">extends</span> <span class="hljs-title" style="box-sizing: border-box; color: rgb(102, 0, 102);">CoordinatorLayout</span>.<span class="hljs-title" style="box-sizing: border-box; color: rgb(102, 0, 102);">Behavior</span><<span class="hljs-title" style="box-sizing: border-box; color: rgb(102, 0, 102);">FloatingActionButton</span>> {</span>
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">private</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">static</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">final</span> String TAG = RotateBehavior.class.getSimpleName();

<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">public</span> <span class="hljs-title" style="box-sizing: border-box;">RotateBehavior</span>() {
}

<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">public</span> <span class="hljs-title" style="box-sizing: border-box;">RotateBehavior</span>(Context context, AttributeSet attrs) {
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">super</span>(context, attrs);
}

<span class="hljs-annotation" style="color: rgb(155, 133, 157); box-sizing: border-box;">@Override</span>
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">public</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">boolean</span> <span class="hljs-title" style="box-sizing: border-box;">layoutDependsOn</span>(CoordinatorLayout parent, FloatingActionButton child, View dependency) {
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> dependency <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">instanceof</span> Snackbar.SnackbarLayout;
}

<span class="hljs-annotation" style="color: rgb(155, 133, 157); box-sizing: border-box;">@Override</span>
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">public</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">boolean</span> <span class="hljs-title" style="box-sizing: border-box;">onDependentViewChanged</span>(CoordinatorLayout parent, FloatingActionButton child, View dependency) {
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">float</span> translationY = getFabTranslationYForSnackbar(parent, child);
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">float</span> percentComplete = -translationY / dependency.getHeight();
child.setRotation(-<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">90</span> * percentComplete);
child.setTranslationY(translationY);
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">false</span>;
}

<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">private</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">float</span> <span class="hljs-title" style="box-sizing: border-box;">getFabTranslationYForSnackbar</span>(CoordinatorLayout parent,
FloatingActionButton fab) {
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">float</span> minOffset = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>;
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">final</span> List<View> dependencies = parent.getDependencies(fab);
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> (<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">int</span> i = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>, z = dependencies.size(); i < z; i++) {
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">final</span> View view = dependencies.get(i);
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> (view <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">instanceof</span> Snackbar.SnackbarLayout && parent.doViewsOverlap(fab, view)) {
minOffset = Math.min(minOffset,
ViewCompat.getTranslationY(view) - view.getHeight());
}
}

<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">return</span> minOffset;
}
}</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">1</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">2</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">3</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">4</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">5</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">6</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">7</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">8</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">9</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">10</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">11</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">12</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">13</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">14</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">15</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">16</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">17</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">18</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">19</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">20</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">21</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">22</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">23</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">24</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">25</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">26</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">27</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">28</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">29</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">30</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">31</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">32</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">33</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">34</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">35</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">36</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">37</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">38</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">39</span></li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">1</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">2</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">3</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">4</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">5</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">6</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">7</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">8</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">9</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">10</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">11</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">12</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">13</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">14</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">15</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">16</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">17</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">18</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">19</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">20</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">21</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">22</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">23</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">24</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">25</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">26</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">27</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">28</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">29</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">30</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">31</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">32</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">33</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">34</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">35</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">36</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">37</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">38</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">39</span></li></ul>
<code class="language-xml hljs  has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span style="font-size:14px;"><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">android.support.design.widget.CoordinatorLayout</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">xmlns:android</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"http://schemas.android.com/apk/res/android"</span>    <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">xmlns:app</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"http://schemas.android.com/apk/res-auto"</span>    <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:id</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"@+id/main_content"</span>    <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_width</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"match_parent"</span>    <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_height</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"match_parent"</span>    <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:fitsSystemWindows</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"true"</span>></span>    <span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">android.support.design.widget.FloatingActionButton</span>        <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:id</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"@+id/fab"</span>        <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_width</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"wrap_content"</span>        <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_height</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"wrap_content"</span>        <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_gravity</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"end|bottom"</span>        <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:layout_margin</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"@dimen/fab_margin"</span>        <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">android:src</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"@drawable/ic_done"</span>        <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">app:layout_behavior</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"com.meizu.coordinatorlayoutdemo.RotateBehavior"</span>/></span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"></<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">android.support.design.widget.CoordinatorLayout</span>></span></span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">1</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">2</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">3</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">4</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">5</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">6</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">7</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">8</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">9</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">10</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">11</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">12</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">13</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">14</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">15</span></li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">1</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">2</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">3</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">4</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">5</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">6</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">7</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">8</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">9</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">10</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">11</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">12</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">13</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">14</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-size:14px;">15</span></li></ul>

效果: 
Android实用技术: CoordinatorLayout使用详解

综上,基本覆盖了CoordinatorLayout的使用方式。


注:本文转自:http://blog.csdn.net/xyz_lmn/article/details/48055919,仅作学习交流,请谅解。