使用 RecyclerView 輕掃以重新整理
要使用 RecyclerView 新增“ 滑動以重新整理” 佈局,請將以下內容新增到“活動/片段”佈局檔案中: ****
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:scrollbars="vertical" />
</android.support.v4.widget.SwipeRefreshLayout>
在你的 Activity / Fragment 中新增以下內容以初始化 SwipeToRefreshLayout :
SwipeRefreshLayout mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.refresh_layout);
mSwipeRefreshLayout.setColorSchemeResources(R.color.green_bg,
android.R.color.holo_green_light,
android.R.color.holo_orange_light,
android.R.color.holo_red_light);
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
// Execute code when refresh layout swiped
}
});