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() { //下拉刷新執行的刷新數據操做,建議在一個子線程中進行操做 } });