不仅仅是pulltorefresh才干够下拉刷新

开源项目pull-to-refresh比較火热,可实现各种形式的下拉刷新。然而使用该项目你就不得不引入他的库文件留配合使用。那么有没有一种原生支持的下拉刷新来满足这个懒惰程序元的愿望呢。答案被找到了:官方的组件---SwipeRefreshLayout。

简单介绍:SwipeRefreshLayout是Google在support v4 19.1版本号的library更新的一个下拉刷新组件,使用起来非常方便。能够非常方便的实现Google Now的刷新效果。使用官方自带的控件能够保证通用性以及风格。SwipeRefreshLayout是继承ViewGroup,来实现下拉刷新,它能够包括其它组件。亲測listview、gridview、scrollview可用。可能还包括很多其它。。。。

。。

不得不说,使用起来很的简单

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="com.example.myapplication2.app.MainActivity">

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swip"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ListView
            android:id="@+id/listview"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

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

</RelativeLayout>
你仅仅须要做的就是引入v4包就能够了
android.support.v4.widget.SwipeRefreshLayout

程序实现代码:

swipeRefreshLayout = (SwipeRefreshLayout) getView().findViewById(R.id.listview);

		//旋转三色
		swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright, android.R.color.holo_green_light,
				android.R.color.holo_orange_light, android.R.color.holo_red_light);

		swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

			@Override
			public void onRefresh() {
				new Handler().postDelayed(new Runnable() {

					@Override
					public void run() {
						//刷新数据
						ToastUtils.show(getActivity(),"sfq-=debug-refresh");
						swipeRefreshLayout.setRefreshing(false);
					}
				}, 1000);
			}
		});
swipeRefreshLayout.setRefreshing(false)
这句话是关掉数显效果。

OK,绝对的简单粗暴




posted @ 2017-06-30 13:56  jzdwajue  阅读(130)  评论(0编辑  收藏  举报