开源控件WaveSwipeRefreshLayout的使用

原创
2017/02/09 16:17
阅读数 377

效果如图,下拉后产生一个水滴的效果

1.在你module的build.gradle中添加依赖

dependencies {
    compile 'com.github.recruit-lifestyle:WaveSwipeRefreshLayout:1.6'   
}

repositories {
        maven {
            url "https://jitpack.io"
        }
}

2.在xml中用WaveSwipeRefreshLayout包裹你的控件

    <jp.co.recruit_lifestyle.android.widget.WaveSwipeRefreshLayout
        android:id="@+id/wave_swipe"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </jp.co.recruit_lifestyle.android.widget.WaveSwipeRefreshLayout>

3.在Java代码中使用

public class MainActivity extends AppCompatActivity {

    @BindView(R.id.wave_swipe)
    WaveSwipeRefreshLayout mWaveSwipe;

    Handler mHandler = new Handler();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        //设置小圆圈颜色
        mWaveSwipe.setColorSchemeColors(Color.WHITE, Color.YELLOW,Color.RED,Color.GREEN);
        //设置背景色
        mWaveSwipe.setWaveColor(Color.argb(255,63,81,181));
        //设置刷新监听
        mWaveSwipe.setOnRefreshListener(new WaveSwipeRefreshLayout.OnRefreshListener() {
            @Override public void onRefresh() {
                new Thread() {
                    @Override
                    public void run() {
                        SystemClock.sleep(3000); //do something in background

                        mHandler.post(new Runnable() { //stop refreshing
                            @Override
                            public void run() {
                                //...
                                mWaveSwipe.setRefreshing(false);//调用这个方法结束刷新小圆圈的显示
                            }
                        });

                    }
                }.start();
                
            }
        });


    }
    
}

原网址:https://github.com/recruit-lifestyle/WaveSwipeRefreshLayout

展开阅读全文
打赏
0
1 收藏
分享
加载中
更多评论
打赏
0 评论
1 收藏
0
分享
返回顶部
顶部