SwipeRefreshLayout是Android官方的一个下拉刷新控件,通常咱们使用此布局和一个RecyclerView嵌套使用java
xml中定义android
<android.support.v4.widget.SwipeRefreshLayout android:id="@+id/refreshlayout" android:layout_width="match_parent" android:layout_height="match_parent"> <com.cy.cyrvadapter.recyclerview.GridRecyclerView android:id="@+id/rv" android:layout_width="match_parent" android:layout_height="match_parent" tools:listitem="@layout/item_rv"/> </android.support.v4.widget.SwipeRefreshLayout>
RefreshLayout refreshLayout = findViewById(R.id.refreshlayout);//找到控件实例 refreshLayout.setColorSchemeColors(R.color.colorPrimary);//设置颜色 //设置下拉监听器 refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { //下拉刷新执行的刷新数据操做,建议在一个子线程中进行操做 } });