//其中所用到的依赖
repositories { maven { url "https://jitpack.io" } }
compile 'com.android.support:recyclerview-v7:26.+' compile 'com.github.recruit-lifestyle:WaveSwipeRefreshLayout:1.6'
//添加网络权限
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
//布局main
<jp.co.recruit_lifestyle.android.widget.WaveSwipeRefreshLayout android:id="@+id/wave" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v7.widget.RecyclerView android:id="@+id/recycler" android:layout_width="match_parent" android:layout_height="wrap_content"></android.support.v7.widget.RecyclerView> </jp.co.recruit_lifestyle.android.widget.WaveSwipeRefreshLayout>//代码合集
import android.graphics.Color; import android.os.Bundle; import android.os.Handler; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.StaggeredGridLayoutManager; import java.io.IOException; import java.util.List; import jp.co.recruit_lifestyle.android.widget.WaveSwipeRefreshLayout; import okhttp3.Call; import zhoukao.demo01.com.shuaxin.utils.GsonObjectCallback; import zhoukao.demo01.com.shuaxin.utils.OkHttp3Utils; public class MainActivity extends AppCompatActivity { private RecyclerView recyclerView; private WaveSwipeRefreshLayout mWaveSwipeRefreshLayout; private Handler handler = new Handler(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //找控件 recyclerView = (RecyclerView) findViewById(R.id.recycler);
//瀑布流布局 StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL); recyclerView.setLayoutManager(staggeredGridLayoutManager); mWaveSwipeRefreshLayout = (WaveSwipeRefreshLayout) findViewById(R.id.wave); //设置中间小圆从白色到黑色 mWaveSwipeRefreshLayout.setColorSchemeColors(Color.WHITE, Color.BLACK); //设置整体的颜色 mWaveSwipeRefreshLayout.setWaveColor(Color.argb(255, 255, 0, 0)); //下拉刷新 mWaveSwipeRefreshLayout.setOnRefreshListener(new WaveSwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { handler.postDelayed(new Runnable() { @Override public void run() { //三秒后停止刷新 mWaveSwipeRefreshLayout.setRefreshing(false); } },3000); } }); } }