实现滑动可固定header以及页面刷新

用到的布局:SwiperRefreshLayout,AppBarLayout,ToolBar,CollapsingToolbarLayout,CoordinatorLayout
布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/app_bar"></include>//自定义的ToolBar
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/deduction_record_swipefreshlayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll">
<LinearLayout
android:id="@+id/top"
android:layout_width="match_parent"
android:layout_height="200dp"
android:orientation="horizontal"
android:background="@color/black"
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|enterAlways"></LinearLayout>
</android.support.design.widget.CollapsingToolbarLayout> <!-- 要固定在toolbar上面的控件 -->
<LinearLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:background="@color/gary_bg"
android:orientation="horizontal">
<TextView
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="类型1"/>
<TextView
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="类型2"/>
<TextView
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="类型3"/>
</LinearLayout>
</android.support.design.widget.AppBarLayout>
//可滑动的布局,可以换成ListView之类的
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="200dp"
android:text="1111111111"/>
<TextView
android:layout_width="match_parent"
android:layout_height="200dp"
android:text="22222222"/>
<TextView
android:layout_width="match_parent"
android:layout_height="200dp"
android:text="333333333333"/>
<TextView
android:layout_width="match_parent"
android:layout_height="200dp"
android:text="444444444444"/>
<TextView
android:layout_width="match_parent"
android:layout_height="200dp"
android:text="5555555555"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:padding="@dimen/layout_padding_10dp"
android:background="@color/gary_bg"
android:text="@string/deduction_analyze"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
Java:
SwipeRefreshLayout mRefreshLayout;
AppBarLayout mAppBarLayout;
mRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.deduction_record_swipefreshlayout);
mRefreshLayout.setOnRefreshListener(this); mAppBarLayout = (AppBarLayout) findViewById(R.id.app_bar_layout);
//主要是解决header固定之后会引起刷新,可去除看下效果
mAppBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
Log.i("测试===","verticalOffset:"+verticalOffset);
//顶部可隐藏布局的滑动(verticalOffset类似Y坐标)
if (verticalOffset == 0){
mRefreshLayout.setEnabled(true);
}else{
mRefreshLayout.setEnabled(false);
}
}
});
实现滑动可固定header以及页面刷新的更多相关文章
- struts2 笔记03 异常支持、防止页面刷新和后退、方法验证
Struts2对异常支持(声明式异常.自动的异常处理), 异常处理(运行期异常事务自动回滚) 1. 自定义异常类,继承RuntimeException或Exception实现构造方法. 2. 配置异常 ...
- PHP 页面刷新与跳转的方法汇总
HTML meta标签 <meta http-equiv='content-type' content="text/html;charset=utf-8"/> 实现页面 ...
- flex页面刷新实现
页面刷新:navigateToURL(new URLRequest("javascript:location.reload();"),"_self"); 关闭浏 ...
- 用js判断页面刷新或关闭的方法
Onunload,onbeforeunload都是在刷新或关闭时调用,可以在<script>脚本中通过window.onunload来指定或者在<body>里指定.区别在于on ...
- JavaScript禁用页面刷新
JavaScript禁用页面刷新代码如下: //禁用F5刷新 document.onkeydown = function () { if (event.keyCode == 116) { event. ...
- js中页面刷新和页面跳转的方法总结
.js中cookie的基本用法简介 2009-12-15 js中页面刷新和页面跳转的方法总结 文章分类:Web前端 关键字: javascript js中页面刷新和页面跳转的方法总结 1.histor ...
- ASP.Net中防止页面刷新重复提交的几种方法
[摘要] 目前很多网站都要提交页面插入或更新数据库,比如留言本,一个用户提交留言后,如果按F5,就会重新提交一遍留言,导致数据库出现两条一模一样的留言,本文介绍了几种防止页面刷新,导致重复提交数据的方 ...
- JQuery实现页面刷新滚动条自动滚动到特定位置
var cotentOffset = $('#6f').offset(); $('.info_box').animate({ scrollLeft: cotentOffset.left }, ); 原 ...
- sharepoint 2010 页面刷新时滚动条位置保持不变 Controlling scrollbar position on postback
sharepoint 2010 页面刷新时滚动条位置保持不变 Controlling scrollbar position on postback在sharepoint 2010中,如果当前页面的篇幅 ...
随机推荐
- POJ 2253 Frogger(Dijkstra)
传送门 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 39453 Accepted: 12691 Des ...
- [bigdata] 从Cloudera Manager中彻底删除服务器
1. 在CM中主机页里,选定要删除的服务器,选择操作“从群集中删除”. 2. 登录到主机,执行chkconfig,显示有cloudera-scm-agent服务, 执行service cloudera ...
- sift特征
已经有很多博客已经将sift特征提取算法解释的很清楚了,我只是记录一些我不明白的地方,并且记录几个理解sift特征比较好的博客. 1. http://aishack.in/tutorials/sift ...
- 【转】真正从零开始,TensorFlow详细安装入门图文教程!(帮你完成那个最难的从0到1)
AI这个概念好像突然就火起来了,年初大比分战胜李世石的AlphaGo成功的吸引了大量的关注,但其实看看你的手机上的语音助手,相机上的人脸识别,今日头条上帮你自动筛选出来的新闻,还有各大音乐软件的歌曲& ...
- CentOS7下默认目录安装mono+jexus教程
一.阅读前须知: 1.本文属于安装完Centos7之后的步骤 2.如果还不了解mono,请点击mono 3.本篇主要内容是使用默认目录安装mono+jexus教程,使用自定义目录请查看使用自定义目录安 ...
- Error configuring application listener of class。。。NoClassDefFoundError。。某Listener 之启动tomcat报错
当你启动tomcat的时候如果报类似下面的错误: WARNING: [SetContextPropertiesRule]{Context} Setting property 'source' to ' ...
- 使用 Weinre 调试移动网站及 PhoneGap 应用
在 PC 端,我们可以使用 Firebug 或者 Chrome 开发人员工具方便的调试网站或者 Web 应用.但是,当我们想在移动端调试站点或者应用的时候,这些工具就派不上用场了.因此,移动开发人员都 ...
- Hadoop基础——第一弹:Hadoop介绍
一.基础 1.了解Java.Linux操作系统相关知识 2.如需精进,应为水平要达到一定标准,能够阅读国外相关技术网站,eg:http://hadoop.apache.org/ 二.什么是Hadoop ...
- Thrift的TJsonProtocol协议分析
Thrift协议实现目前有二进制协议(TBinaryProtocol),紧凑型二进制协议(TCompactProtocol)和Json协议(TJsonProtocol). 前面的两篇文字从编码和协议原 ...
- HTTP协议 请求篇
http请求有三部分组成,分别是:请求行.消息报头.请求正文. 1.请求行是以一个方法符号开头,以空格分开,后面跟着请求的URL和协议的版本,格式如下 : Method Request-URL HTT ...