Android 开源框架 ( 十五 ) 下拉刷新框架 --- SwipeRefreshLayout
SwipeRefreshLayout是Google官方更新的一个Widget,可以实现下拉刷新的效果。完整包名:android.support.v4.widget.SwipeRefreshLayout .
一. 布局
<android.support.v4.widget.SwipeRefreshLayout android:id="@+id/srl" android:layout_width="match_parent" android:layout_height="wrap_content"> ............. </android.support.v4.widget.SwipeRefreshLayout>
二. Activity继承SwipeRefreshLayout刷新监听
implements SwipeRefreshLayout.OnRefreshListener
三.添加监听
srl.setOnRefreshListener(this);
四.改变刷新图标颜色
CommonUtils.setColorSchemeResources(srl); public class CommonUtils { /** * 统一维护,方便修改 * * @param sr_layout 下拉控件 */ public static void setColorSchemeResources(SwipeRefreshLayout sr_layout) { if (sr_layout != null) { sr_layout.setColorSchemeResources(R.color.refresh1, R.color.refresh2, R.color .refresh3, R .color.refresh4); } } }
五. 重写SwipeRefreshLayout刷新监听事件
//刷新 @Override public void onRefresh() { isPullToRefreshRequest = true; //刷新数据 } //加载动画结束 @Override public void onAllRequestsFinished() { super.onAllRequestsFinished(); srl.setRefreshing(false); }