android当中有自带的一款刷新效果,不需要自己重新写,也不需要自己配置,总的来说非常好用,只不过是效果比较单调,不过比网上盛传的那些下拉刷新仅仅是个箭头的效果好很多。
首先先把需要刷新的xml内容用以下代码包裹住:
<android.support.v4.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/swipe_container">
<!--添加需要刷新的内容-->
</android.support.v4.widget.SwipeRefreshLayout>
然后在逻辑代码中实现接口也就是在implements后添加SwipeRefreshLayout.OnRefreshListener
同时定义:
private SwipeRefreshLayout mSwipeLayout;//下拉刷新
然后在布置UI的部分中添加代码:
//下拉刷新配置
mSwipeLayout = (SwipeRefreshLayout)view.findViewById(R.id.swipe_container);
mSwipeLayout.setOnRefreshListener(this);
// 设置下拉圆圈上的颜色