Android控件(一)下拉刷新:SwipeRefreshLayout
须要注意的是SwipeRefreshLayout以下仅仅能够有一个直接子节点。
布局文件例如以下。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="MergeRootFrame" >
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>
主程序例如以下:
package com.francis.swiperefreshlayouttest; import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v4.widget.SwipeRefreshLayout;
import android.widget.ArrayAdapter;
import android.widget.ListView; // 布局文件下。<android.support.v4.widget.SwipeRefreshLayout> 仅仅能有一个直接的子类
//
// 主要方法
// setOnRefreshListener(OnRefreshListener): 为布局加入一个Listener
// setRefreshing(boolean): 显示或隐藏刷新进度条
// isRefreshing(): 检查是否处于刷新状态
// setColorSchemeResource(): 设置进度条的颜色主题。最多能设置四种 public class MyActivity extends Activity implements SwipeRefreshLayout.OnRefreshListener{
private SwipeRefreshLayout mSwipeLayout;
private ListView mListView;
private ArrayAdapter<String> mArrayAdapter; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
String[] strings = new String[] {"a","b","c","d"};
mArrayAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,strings);
mSwipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
mSwipeLayout.setOnRefreshListener(this);
//载入颜色是循环播放的。仅仅要没有完毕刷新就会一直循环,color1>color2>color3>color4
mSwipeLayout.setColorSchemeResources(
android.R.color.holo_blue_bright,
android.R.color.holo_green_light,
android.R.color.holo_orange_light,
android.R.color.holo_red_light);
mListView = (ListView)findViewById(R.id.list);
mListView.setAdapter(mArrayAdapter);
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.my, menu);
return true;
} @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(); if (id == R.id.action_grid_view) {
startActivity(new Intent(MyActivity.this,GridViewTest.class));
}
return super.onOptionsItemSelected(item);
} @Override
public void onRefresh() { new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// 停止刷新
mSwipeLayout.setRefreshing(false); }
}, 3000); }
}
Android控件(一)下拉刷新:SwipeRefreshLayout的更多相关文章
- 支持各种控件上/下拉刷新的android-pulltorefresh
android- pulltorefresh 一个强大的拉动刷新开源项目,支持各种控件下拉刷新,如ListView.ViewPager.WevView. ExpandableListView.Grid ...
- 【Android-SwipeRefreshLayout控件】下拉刷新
Android自带API ,V4包下面的下拉刷新控件 android.support.v4.widget.SwipeRefreshLayout SwipeRefreshLayout只能包含一个控件 布 ...
- Qt qml listview 列表视图控件(下拉刷新、上拉分页、滚动轴)
Qt qml listview下拉刷新和上拉分页主要根据contentY来判断.但要加上顶部下拉指示器.滚动条,并封装成可简单调用的组件,着实花了我不少精力:) [先看效果] [功能] 下拉刷新 ...
- 使用谷歌提供的SwipeRefreshLayout下拉控件进行下拉刷新的实现数据的刷新
package com.loaderman.swiperefreshdemo; import android.os.Bundle; import android.os.Handler; import ...
- Android仿苹果版QQ下拉刷新实现(一) ——打造简单平滑的通用下拉刷新控件
前言: 忙完了结婚乐APP的开发,终于可以花一定的时间放在博客上了.好了,废话不多说,今天我们要带来的效果是苹果版本的QQ下拉刷新.首先看一下目标效果以及demo效果: 因为此效果实现的步骤 ...
- Android 之WebView实现下拉刷新和其他相关刷新功能
最近项目中需要用到WebView下拉刷新的功能,经过查找资料终于完成了此功能,现在拿出来和大家分享一下.希望对大家有所帮助. 效果如下图: 代码: activity.xml <?xml ve ...
- Android Material Design控件使用(四)——下拉刷新 SwipeRefreshLayout
使用下拉刷新SwipeRefreshLayout 说明 SwipeRefreshLayout是Android官方的一个下拉刷新控件,一般我们使用此布局和一个RecyclerView嵌套使用 使用 xm ...
- Android仿苹果版QQ下拉刷新实现(二) ——贝塞尔曲线开发"鼻涕"下拉粘连效果
前言 接着上一期Android仿苹果版QQ下拉刷新实现(一) ——打造简单平滑的通用下拉刷新控件 的博客开始,同样,在开始前我们先来看一下目标效果: 下面上一下本章需要实现的效果图: 大家看到这个效果 ...
- Android下拉刷新-SwipeRefreshLayout,RecyclerView完全解析之下拉刷新与上拉加载SwipeRefreshLayout)
SwipeRefrshLayout是Google官方更新的一个Widget,可以实现下拉刷新的效果.该控件集成自ViewGroup在support-v4兼容包下,不过我们需要升级supportlibr ...
- Android下拉刷新SwipeRefreshLayout简单用法
之前一直都想用下拉刷新,感觉上是庞大的工程,所以搁置了.现在学习了一下其实真的超级简单. 看了<第一行代码>以及 https://www.jianshu.com/p/3c402a9e4b7 ...
随机推荐
- HDU1242 Rescue(BFS+优先队列)
Rescue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- UVA 100 - The 3n+1 problem (3n+1 问题)
100 - The 3n+1 problem (3n+1 问题) /* * 100 - The 3n+1 problem (3n+1 问题) * 作者 仪冰 * QQ 974817955 * * [问 ...
- 二十六、Jcreator使用初步
摘自http://blog.csdn.net/liujun13579/article/details/7751464 二十六.Jcreator使用初步 Jcreator是一个小巧灵活的Java开发工具 ...
- CSS3初步
一.CSS与CSS3的区别 非常简单,CSS代表"Casading Style Sheets",就是样式表,是一种替代并为网站添加样式的标记性语言.现在所使用的CSS基本是在199 ...
- execute immediate的简单用法(oracle)
直接上示例代码: create or replace procedure proc_test( --参数区域 ) is --变量区域 --sql脚本 v_sql ) :=''; --记录学生数量 v_ ...
- Nginx学习之四-Nginx进程同步方式-自旋锁(spinlock)
自旋锁简介 Nginx框架使用了三种消息传递方式:共享内存.套接字.信号. Nginx主要使用了三种同步方式:原子操作.信号量.文件锁. 基于原子操作,nginx实现了一个自旋锁.自旋锁是一种非睡眠锁 ...
- 详细介绍Qt,ffmpeg 和SDL开发
Qt 与 ffmpeg 与 SDl 教程是本文要介绍的内容,从多个角度介绍本文,运用了qmake,先来看内容. 1. 注释 从“ #” 开始,到这一行结束. 2. 指定源文件 1. ...
- Django 从零開始
1.下载安装django 方法1: pip install Django==1.6.5 測试是否成功安装 : ~$ python import django ~$ (1, 6, 5, 'final', ...
- 关于vnc连接闪退问题的设置
设置如下: 依次点Option-->Advanced-->Expert找到ColourLevel,默认值是pal8,修改为rgb222或full.
- android一些常用的代码2(收藏)
1.收集设备信息,用于信息统计分析 public static Properties collectDeviceInfo(Context context) { Properties mDeviceCr ...