用SwipeRefreshLayout,一般是包裹一个recyclerview
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/news_list"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.SwipeRefreshLayout>
然后去
private SwipeRefreshLayout refreshLayout;
refreshLayout = findViewById(R.id.refresh);
refreshLayout.setColorSchemeResources(R.color.colorPrimary);
initRefresh();
initData里就是你自己写得请求数据了
private void initRefresh() {
refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
initData();
}
});
}
更新完之后记得停止转动
refreshLayout.setRefreshing(false);