SwipeRefreshLayout安卓最普通的下拉刷新
来源:互联网 发布:probe软件使用教程 编辑:程序博客网 时间:2024/06/05 22:40
转载请注明作者AndroidMsky及连接
http://blog.csdn.net/AndroidMsky/article/details/53607333
这就是这个系统的效果:
记得好似是半年前或者是更久,我看到了一个下拉刷新的博文,感觉这个小圆圈的加载效果很棒,于是去看看是如何实现的是shape还是图片,还是自定view自己画的啊。结果找了半天未果。后来有一段时间才搞清楚,原来是系统自带的SwipeRefreshLayout在5.0新的显示效果。哦哦,让我夸(黑)一发,安卓也有系统控件直接拿出来就很不错的了。MD设计万岁。算了不扯了,接下来介绍一下这种很简单的系统下拉刷新的使用方式吧。
首先这货是实现NestedScrollingChild和NestedScrollingParent两个接口的Viewgroup,里面放ScrollView RecyclerView listview都可以的。
xml中这样用就可以了:
<android.support.v4.widget.SwipeRefreshLayout android:id="@+id/swipe_container" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ScrollView android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#d2d284"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/textView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:paddingTop="10dp" android:text="下拉刷新" android:textSize="20sp" android:textStyle="bold"/> <TextView android:id="@+id/textView2" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:onClick="re" android:paddingTop="10dp" android:text="下拉刷新" android:textSize="20sp" android:textStyle="bold"/> <ImageView android:layout_width="match_parent" android:layout_height="900dp" android:scaleType="fitXY" android:src="@mipmap/ic_launcher"/> </LinearLayout> </ScrollView></android.support.v4.widget.SwipeRefreshLayout>
然后find各个控件,并写一个接口模拟一下耗时任务:
SwipeRefreshLayout.OnRefreshListener listener;listener = new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { mTextView.setText("正在刷新"); new Handler().postDelayed(new Runnable() { @Override public void run() { // TODO Auto-generated method stub mTextView.setText("刷新完成"); swipeRefreshLayout.setRefreshing(false); } }, 3000); } };
如果想不下拉直接触发载入中状态:
private void doReF() {
swipeRefreshLayout.setRefreshing(true); listener.onRefresh();}
如果在onCreat中调动一定加在post里:
private void doReF() { swipeRefreshLayout.setRefreshing(true); listener.onRefresh(); }
一般的调用:
private void doReF() { swipeRefreshLayout.setRefreshing(true); listener.onRefresh(); }
例子比较简单,笔者也是回味了一下安卓开发路上的小小波澜。
欢迎关注作者。欢迎评论讨论。欢迎拍砖。 如果觉得这篇文章对你有帮助,欢迎打赏, 欢迎star,Fork我的github。 喜欢作者的也可以Follow。也算对作者的一种支持。 本文Github代码链接
https://github.com/AndroidMsky/MskySwipeRefreshLayout
欢迎加作者自营安卓开发交流群:308372687
—————————————————————————————
作者推荐:
安卓自定义view滚动数据显示
http://blog.csdn.net/androidmsky/article/details/53009886
RecyclerView下拉刷新分页加载性能优化和Gilde配合加载三部曲
http://blog.csdn.net/androidmsky/article/details/53115818
打造企业级网络请求框架集合retrofit+gson+mvp
http://blog.csdn.net/androidmsky/article/details/52882722 安卓手机自动接起QQ视频秒变摄像头
http://blog.csdn.net/androidmsky/article/details/53066441
微信自动抢红包
http://blog.csdn.net/androidmsky/article/details/53490459
—————————————————————————————
- SwipeRefreshLayout安卓最普通的下拉刷新
- 不一样的下拉刷新-----SwipeRefreshLayout
- 不一样的下拉刷新-----SwipeRefreshLayout
- 官方的下拉刷新SwipeRefreshLayout
- 自定义的下拉刷新SwipeRefreshLayout
- 关闭SwipeRefreshLayout的下拉刷新
- SwipeRefreshLayout下拉刷新的使用
- google推出的SwipeRefreshLayout下拉刷新用法
- google推出的SwipeRefreshLayout下拉刷新用法
- google推出的SwipeRefreshLayout下拉刷新用法
- google推出的SwipeRefreshLayout下拉刷新用法
- Android SwipeRefreshLayout GMail的下拉刷新效果
- 下拉刷新SwipeRefreshLayout的扩展两个方向
- 官方下拉刷新控件SwipeRefreshLayout的使用
- SwipeRefreshLayout谷歌自己的下拉 刷新
- Android 下拉刷新控件SwipeRefreshLayout 的使用
- google推出的SwipeRefreshLayout下拉刷新用法
- 简单的下拉刷新以及优化--SwipeRefreshLayout
- study-14: rsync(2)
- 基于状态机思想的按键扫描程序支持单按,连续按,长按模式。
- dell电脑 win10 Ubuntu双系统 Ubuntu无法连接网络
- Migration
- web前端之JavaScript高级程序设计一:变量、作用域
- SwipeRefreshLayout安卓最普通的下拉刷新
- ThinkPHP 模板解析类Template分析
- 网页嵌套
- 蛇形矩阵(上三角形)
- Android属性动画——ObjectAnimator
- eclipse报错:Compilation unit name must end with .java, or one of the registered Java-like exten
- Python经典书籍推荐
- Ramp-Up Period 与 Think time
- Article - World, View and Projection Transformation Matrices