1.效果图

2.新建SrcollingActivity后生成代码为:

<?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="myapplication.com.myceshi.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"> <ImageView
android:layout_width="match_parent"
android:scaleType="centerCrop"
android:layout_height="match_parent"
android:src="@mipmap/a"/>
<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" /> </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>

3.主要内容布局是

<?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="myapplication.com.myceshi.ScrollingActivity"
tools:showIn="@layout/activity_scrolling"> <LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"> <TextView
android:layout_width="match_parent"
android:layout_height="60dp"
android:lineSpacingExtra="4dp"
android:textSize="20dp"
android:text="内容”
android:textColor="@color/colorAccent"/> </LinearLayout> </android.support.v4.widget.NestedScrollView>

4.onCreate

 @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scrolling);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
    // 设置返回键和菜单栏可用,可见
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
/**
* 悬浮球点击事件
* */
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();
}
});
}
  @Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId(); /**
*
* 菜单set事件
* */
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
Toast.makeText(getApplicationContext(),"setting1",Toast.LENGTH_SHORT).show();
return true;
}
/**
* 菜单set事件
* */
if (id == R.id.action_set) {
Toast.makeText(getApplicationContext(),"Setting2",Toast.LENGTH_SHORT).show(); return true;
}
/**
* 返回键事件
* */
if(id==android.R.id.home){
Toast.makeText(getApplicationContext(),"返回键",Toast.LENGTH_SHORT).show();
return true;
} return super.onOptionsItemSelected(item);
}
 @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_detail_, menu);
return true;
}
<menu 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"
tools:context="myapplication.com.myplattvok.avtivity.Detail_Activity">
<item
android:id="@+id/action_settings"
android:orderInCategory=""
android:title="@string/action_settings"
app:showAsAction="never" />
</menu>

CoordinatorLayout:android之ScrollingActivity的更多相关文章

  1. Android开发学习之路-Android Design Support Library使用(CoordinatorLayout的使用)

    效果图: 上面的这个图有两个效果是,一个是顶部的图片,在上滑之后会隐藏起来并且显示出一个ToolBar(ToolBar类似于ActionBar,但是只有ToolBar是兼容Material Desig ...

  2. Android开发笔记(一百三十四)协调布局CoordinatorLayout

    协调布局CoordinatorLayout Android自5.0之后对UI做了较大的提升.一个重大的改进是推出了MaterialDesign库,而该库的基础即为协调布局CoordinatorLayo ...

  3. Android控件大全(四)——CoordinatorLayout

    CoordinatorLayout 其实就是个高级的FrameLayout,用于协调子布局要使用该控件,需要再gradle中加入: compile 'com.android.support:desig ...

  4. Android CollapsingToolbarLayout使用介绍

    我非常喜欢Material Design里折叠工具栏的效果,bilibili Android客户端视频详情页就是采用的这种设计.这篇文章的第二部分我们就通过简单的模仿bilibili视频详情页的实现来 ...

  5. CoordinatorLayout使用全解析

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/u012124438/article/details/56701641 CoordinatorLayo ...

  6. CoordinatorLayout 自定义Behavior并不难,由简到难手把手带你飞

    先来看看最终的效果~~ 本文同步至博主的私人博客wing的地方酒馆 嗯..一个是头像上移的 另一个是模仿UC浏览器的. (PД`q.)你不是说!有三款的吗,怎么只有两款!!!! 不要急嘛... 说了从 ...

  7. 【转】【翻】Android Design Support Library 的 代码实验——几行代码,让你的 APP 变得花俏

    转自:http://mrfufufu.github.io/android/2015/07/01/Codelab_Android_Design_Support_Library.html [翻]Andro ...

  8. Android 优秀UI控件 ---- FlowingDrawer

    1,前天在git上看到了一个不错的控件 ,最近两天项目也没有那么赶了,就抽时间来写写代码,锻炼一下手感,先看一下效果吧. 2 整体来看 ,主要是有两块来实现的,①主界面的RecyclerView ,② ...

  9. Android Design Support Library 的 代码实验——几行代码,让你的 APP 变得花俏

    原文:Codelab for Android Design Support Library used in I/O Rewind Bangkok session--Make your app fanc ...

随机推荐

  1. testdirector

    TestDirector是全球最大的软件测试工具提供商Mercury Interactive公司生产的企业级测试管理工具,也是业界第一个基于Web的测试管理系统

  2. 编译OpenCV遇到Qmake问题

    1.Ubuntu安装OpenCv,出现:qmake: could not exec '/usr/lib/x86_64-linux-gnu/qt4/bin/qmake': No such file or ...

  3. 【技术累积】【点】【java】【8】maven常用命令(持续更新)

    建立 mvn archetype:generate -DgroupId=com.andy.test -DartifactId=test-project -Dversion=0.0.1-SNAPSHOT ...

  4. Shader渲染动画

    一.概述 先看一下Shader类的介绍: /** * Shader is the based class for objects that return horizontal spans of col ...

  5. 解决python3在sublim Text3中中文乱码的问题

    在Tool >> BulidingSystem 中  新建 python3 写入如下代码 { "cmd": ["C:/python3/python.exe&q ...

  6. SQL更新字段内容部分值

    UPDATE att_allSET attachment = REPLACE(attachment, 'pw/', '')WHERE (attachment LIKE 'pw/%')

  7. 4.1、Ansible模块

    ansible-doc -l    列出所有模块 ansible-doc 模块名    查看模块的help说明 ansible-doc -s  module_name:获取指定模块的使用信息 ***文 ...

  8. 可执行程序无法在Linux上运行,显示line 1: syntax error: word unexpected (expecting ") .

    [问题]用arm-linux-gcc编译出来的可执行文件clkCtl,下载到板子上,在Linux下不能运行:./clkCtl: line 1: syntax error: word unexpecte ...

  9. Redis 报错:MISCONF Redis is configured to save RDB snapshots

    MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Com ...

  10. 使用Spring的MailSender发送邮件

    第1步:扫描邮件发送的属性配置 <context:property-placeholder location="/config/mail.properties" ignore ...