不只是pulltorefresh才可以下拉刷新

来源:互联网 发布:手机淘宝账号怎么查看 编辑:程序博客网 时间:2024/06/09 18:50

开源项目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() {@Overridepublic void onRefresh() {new Handler().postDelayed(new Runnable() {@Overridepublic void run() {//刷新数据ToastUtils.show(getActivity(),"sfq-=debug-refresh");swipeRefreshLayout.setRefreshing(false);}}, 1000);}});
swipeRefreshLayout.setRefreshing(false)
这句话是关掉数显效果。

OK,绝对的简单粗暴!!


1 0