实现滑动可固定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中,如果当前页面的篇幅 ...
随机推荐
- oracle--逻辑对象--bai
1 序列 sequence oracle特有.实现"自增"或"自减"的逻辑对象. 2 同义词 synonym 对表取别名,该别名被永久存储. 比视图更省资源. ...
- C# .Net :Excel NPOI导入导出操作教程之将Excel文件读取并写到数据库表,示例分享
using (FileStream fileReader = File.OpenRead(@"C:\Users\Administrator\Desktop\112.xls")) ...
- Mac下maven工程的创建,并搭建SSH环境
最近项目有用到maven,就特地学了一下.maven的一句话攻略就是,项目托管.帮你解决各种项目琐事:清理,导包....等等. 首先先到apach官网去下载一个maven的包,http://maven ...
- thinkphp中的查询语句
<?php namespace Admin\Controller; use Think\Controller; class MainController extends Controller { ...
- CSS--background
它的组合写法: background-color, background-image, background-repeat,backgroundattachment, background-posit ...
- centos 7.0 安装nginx 1.117
php官方下载地址 http://cn2.php.net/downloads.php
- SQL Sever无法打开链接对话框,未将对象引用设置到对象的实例。(AppIDPackage)
前几天刚做完系统,先装的是SQL Sever2008,装完后还试了一下,OK~没问题,然后就继续装VS2012等一些软件.搞到很晚没有继续试试就睡了,第二天运行SSMS出问题了..(如图 1.0 所示 ...
- 忘记mysql root 密码修改小技巧
首先我说一下我的情况,我并不是忘记了我的root密码,只不过是我在使用phpmyadmin的时候更改密码的时候选择了如图1 的这个方法将密码加密并更改了,然后就再次登录的时候登录不上,所以对于菜鸟级的 ...
- ls目录内容
ls:列出目录内容 1.常用参数: -a, –all 列出目录下的所有文件,包括以 . 开头的隐含文件(常用) -A 同-a,但不列出“.”(表示当前目录)和“..”(表示当前目录的父目录). -c ...
- mysql_config 问题
1 .you should have mysql_config available in $PATH For CentOS: yum install mysql-devel For openSUSE: ...