SwipeRefreshLayout 继承与ViewGroup, 只能包含一个子组件。

主要接口:

//设置手势滑动监听器
setOnRefreshListener(SwipeRefreshLayout.OnRefreshListener listener)
//设置进度圈的背景色
setProgressBackgroundColor(int colorRes)
//设置进度动画的颜色
setColorSchemeResources(int… colorResIds)
//设置组件的刷洗状态
setRefreshing(Boolean refreshing)
//设置进度圈的大小,只有两个值:DEFAULT、LARGE
setSize(int size)
//是否可用
setEnabled(boolean enable)

xml示例:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:id="@+id/swipeLayout" >

    <ListView 
        android:id="@+id/mylist"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</android.support.v4.widget.SwipeRefreshLayout>

java示例:

    //第一次进来就显示刷新效果
    swipeRefreshLayout.setProgressViewOffset(false, 0, (int) TypedValue
            .applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, getResources()
                    .getDisplayMetrics()));
    swipeRefreshLayout.setRefreshing(true);


    swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout);
    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            webview.reload();
        }
    });

完整例子见 github

标签: none

评论已关闭