这段时间用来SwipeRefreshLayout,代码优化的时候发现需要一进入界面就开启刷新效果,开始以为使用如下方式可以达到效果:
SwipeRefreshLayout.setRefersh(true);
new Handler().postDelay(new Runable{
public void run(){
//这里进行数据的加载
SwipeRefreshLayout.setRefersh(false);
]
},2000);
经过测试发现并没有达到效果 SwipeRefreshLayout.setRefersh(true); 并没有运行,然后就去找资料,测试了一下有几种方法度可以达到效果,其中最简单的是如下:
SwipeRefreshLayout.setProgressViewOffset(false, 0, 30);
SwipeRefreshLayout.setRefersh(true);
new Handler().postDelay(new Runable{
public void run(){
//这里进行数据的加载
SwipeRefreshLayout.setRefersh(false);
]
},2000);
只需在前面加上SwipeRefreshLayout.setProgressViewOffset(false, 0, 30);方法,那这个方法起到了什么作用呢?查看源码得知:
* The refresh indicator starting and resting position is always positioned * near the top of the refreshing content. This position is a consistent * location, but can be adjusted in either direction based on whether or not * there is a toolbar or actionbar present.
三个参数的意思分别是:1.Scale表示这个Progress是否缩放 2.start和end就是那刷新进度条展示的相对于默认的展示位置,start和end组成一个范围,在这个y轴范围就是那个圆形进度ProgressView展示的位置。