//第一步 导入依赖
implementation 'com.github.recruit-lifestyle:WaveSwipeRefreshLayout:1.6'
//第二步 写xml布局
<jp.co.recruit_lifestyle.android.widget.WaveSwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/main_swipe">
<ListView
android:id="@+id/main_list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</jp.co.recruit_lifestyle.android.widget.WaveSwipeRefreshLayout>
//第三步 Activity里使用:
private void initView() {
main_list = (ListView) findViewById(R.id.main_list);
main_swipe = (WaveSwipeRefreshLayout) findViewById(R.id.main_swipe);
main_swipe.setOnRefreshListener(new WaveSwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
//请在此处刷新列表
new Task().execute();
}
});
}
private class Task extends AsyncTask<Void, Void, String[]> {
@Override
protected String[] doInBackground(Void... voids) {
try {
//执行了2秒的睡眠
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return new String[0];
}
@Override protected void onPostExecute(String[] result) {
//刷新列表后,调用setdreshing ( false )。动画结束
main_swipe.setRefreshing(false);
super.onPostExecute(result);
}
}
//最好改成16的
minSdkVersion 16
//-----------------------------------------------------------------------完-----------------------------------------------------------------------------------