简单介绍一下谷歌提供的下拉刷新组件SwipeRefreshLayout
1、包名:android.support.v4.widget
2、用SwipeRefreshLayout包裹一个需要用到下拉刷新的组件
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>
</ScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
3、使用
//绑定
SwipeRefreshLayout refreshLayout= (SwipeRefreshLayout)findViewById(R.id.swipeRefreshLayout);
//下拉松手后执行
refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
}
});
refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
}
});
//设置刷新条的颜色
setColorSchemeColors(int... colors);
//隐藏刷新头
refreshLayout.setRefreshing(false);
4、效果图