1.new project -> Scrolling Activity

2.Layout xml code

activity_scrolling.xml

 <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.eve.coordinatorlayoutsample.ScrollingActivity"> <android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay"> <android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"> <android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay" /> <ImageView
android:src="@mipmap/bird"
app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"
android:minHeight="?attr/actionBarSize"/> </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout> <include layout="@layout/content_scrolling" /> <android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
app:layout_anchor="@id/app_bar"
app:layout_anchorGravity="bottom|end"
app:srcCompat="@android:drawable/ic_dialog_email" /> </android.support.design.widget.CoordinatorLayout>

content_scrolling.xml

 <?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.eve.coordinatorlayoutsample.ScrollingActivity"
tools:showIn="@layout/activity_scrolling"> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/text_margin"
android:text="@string/large_text" /> </android.support.v4.widget.NestedScrollView>

3.Activity code

 public class ScrollingActivity extends AppCompatActivity {

     @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scrolling);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
}

最新文章

  1. hdu5651 xiaoxin juju needs help (多重集的全排列+逆元)
  2. 分布式大数据高并发的web开发框架
  3. [持续更新] 文章列表 last updated SEP 18, 2016
  4. PHP $_SERVER的详细参数及说明
  5. APACHE如何里一个站点绑定多个域名?用ServerAlias
  6. [转]2-SAT问题及其算法
  7. JFreeChart入学教程
  8. POP动画引擎中Layer与CALayer的一点区别
  9. Linux SCP命令复制传输文件的用法
  10. JDK8新特性面试
  11. JDBC进阶
  12. JAVA之JDBC的简单使用(Mysql)
  13. 用swing做一个简单的正则验证工具
  14. 洛谷P4316 绿豆蛙的归宿
  15. DBS:CUPhone
  16. django之setup()
  17. java中 this 关键字的三种用法
  18. wagon-maven-plugin实现自动打包部署到服务器
  19. Postman 常用测试结果验证及使用技巧
  20. SpringBoot (四) :thymeleaf 使用详解

热门文章

  1. nyoj 8 一种排序(用vector,sort,不用set)
  2. Codeforces Round #239(Div. 2) 做后扯淡玩
  3. poj 3925 枚举+prime
  4. hdu 2545 并查集 树上战争
  5. Code(poj 17801)
  6. Tyvj1139 向远方奔跑(APIO 2009 抢掠计划)
  7. 洛谷—— P1187 3D模型
  8. Android: MediaRecorder start failed
  9. Linux内核project导论——前言
  10. HDU 4499 Cannon (暴力搜索)