CoordinatorLayout:android之ScrollingActivity
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的更多相关文章
- Android开发学习之路-Android Design Support Library使用(CoordinatorLayout的使用)
效果图: 上面的这个图有两个效果是,一个是顶部的图片,在上滑之后会隐藏起来并且显示出一个ToolBar(ToolBar类似于ActionBar,但是只有ToolBar是兼容Material Desig ...
- Android开发笔记(一百三十四)协调布局CoordinatorLayout
协调布局CoordinatorLayout Android自5.0之后对UI做了较大的提升.一个重大的改进是推出了MaterialDesign库,而该库的基础即为协调布局CoordinatorLayo ...
- Android控件大全(四)——CoordinatorLayout
CoordinatorLayout 其实就是个高级的FrameLayout,用于协调子布局要使用该控件,需要再gradle中加入: compile 'com.android.support:desig ...
- Android CollapsingToolbarLayout使用介绍
我非常喜欢Material Design里折叠工具栏的效果,bilibili Android客户端视频详情页就是采用的这种设计.这篇文章的第二部分我们就通过简单的模仿bilibili视频详情页的实现来 ...
- CoordinatorLayout使用全解析
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/u012124438/article/details/56701641 CoordinatorLayo ...
- CoordinatorLayout 自定义Behavior并不难,由简到难手把手带你飞
先来看看最终的效果~~ 本文同步至博主的私人博客wing的地方酒馆 嗯..一个是头像上移的 另一个是模仿UC浏览器的. (PД`q.)你不是说!有三款的吗,怎么只有两款!!!! 不要急嘛... 说了从 ...
- 【转】【翻】Android Design Support Library 的 代码实验——几行代码,让你的 APP 变得花俏
转自:http://mrfufufu.github.io/android/2015/07/01/Codelab_Android_Design_Support_Library.html [翻]Andro ...
- Android 优秀UI控件 ---- FlowingDrawer
1,前天在git上看到了一个不错的控件 ,最近两天项目也没有那么赶了,就抽时间来写写代码,锻炼一下手感,先看一下效果吧. 2 整体来看 ,主要是有两块来实现的,①主界面的RecyclerView ,② ...
- Android Design Support Library 的 代码实验——几行代码,让你的 APP 变得花俏
原文:Codelab for Android Design Support Library used in I/O Rewind Bangkok session--Make your app fanc ...
随机推荐
- Docker的官网在线--中文教程
1.官网界面:https://www.docker.com/tryit/ In this 10-minute tutorial, see how Docker works first-hand: Yo ...
- C# HttpWebRequest post 请求传参数
Dictionary<string, string> parameters = new Dictionary<string, string>(); //参数列表 paramet ...
- poj 2955 Brackets 【 区间dp 】
话说这题自己折腾好久还是没有推出转移的公式来啊------------------ 只想出了dp[i][j]表示i到j的最大括号匹配的数目--ค(TㅅT)------------------- 后来搜 ...
- map 解析
Observable.of(1, 2, 3) .map { $0 * $0 } .subscribe(onNext: { print($0) }) .disposed(by: disposeBag) ...
- 如何选择优动漫PAINT版本?是个人版还是EX版
优动漫PAINT也就是我们常说的clip studio paint(CSP)的中文版本,它是一款功能强大的动漫绘图软件,适用于个人和专业团队创作,分为个人版和EX版.搭载了绘制漫画和插画所需的所有功能 ...
- ArrayList集合如何存储基本数据类型
ArrayList对象不能存储基本类型,只能存储引用类型的数据.类似 <int> 不能写,但是存储基本数据类型对应的包装类型是可以的. 所以,想要存储基本类型数据, <> 中的 ...
- Intellij IDEA中Mybatis Mapper自动注入警告的6种解决方案
点关注,不迷路:持续更新Java架构相关技术及资讯热文!!! 相信使用Mybaits的小伙伴们一定会经常编写类似如下的代码: 可以看到 userMapper 下有个红色警告.虽然代码本身并没有问题,能 ...
- Python笔记12-----画图Matplotlib
1.matplotlib:pyplot和pylab 如: import pylab as pl pl.figure(figsize=(8,6),dpi=100)[建立的图像大小和图的精度] pl.pl ...
- [模板]Matrix Tree定理
结论:一个图的生成树个数等于它的度数矩阵减邻接矩阵得到的矩阵(基尔霍夫矩阵)的任意一个n-1阶主子式的行列式的绝对值 证明:不会 求法:高斯消元 例题:[HEOI2013]小Z的房间 #include ...
- CENTOS 7发送邮件测试
centos7作为126邮箱客户端发送邮件测试. 首先安装客户端软件: yum install sendmail mailx -y 配置邮箱设置: 开启smtp发件协议 配置授权码,写入配置文件. 追 ...