不一样的下拉刷新-----SwipeRefreshLayout

来源:互联网 发布:flash8 mac 编辑:程序博客网 时间:2024/06/03 05:07

转自http://blog.csdn.net/hpu_zyh/article/details/43193163

按照惯例,先上那个效果图

       


最近看到好多应用都在使用这种下拉刷新,于是自己搜索了一下,原来这玩意儿是Google提供的SwipeRefreshLayout控件,以前也使用过家伙,但是效果不是这个样子的,是下图的样子,现在Google又改变了其效果

 

使用起来还是非常简单的,在布局中,将android.support.v4.widget.SwipeRefreshLayout包裹在 Listview ScrollViewGridView等控件外部


[html] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:id="@+id/swipeRefreshLayout"  
  4.     android:layout_width="match_parent"  
  5.     android:layout_height="match_parent"  
  6.     android:orientation="vertical" >  
  7.   
  8.     <ListView  
  9.         android:id="@+id/listView"  
  10.         android:layout_width="match_parent"  
  11.         android:layout_height="match_parent"  
  12.         android:footerDividersEnabled="false" />  
  13.   
  14. </android.support.v4.widget.SwipeRefreshLayout>  
[html] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:id="@+id/swipeRefreshLayout"  
  4.     android:layout_width="match_parent"  
  5.     android:layout_height="match_parent"  
  6.     android:orientation="vertical" >  
  7.   
  8.     <ScrollView  
  9.         android:id="@+id/listView"  
  10.         android:layout_width="match_parent"  
  11.         android:layout_height="match_parent" >  
  12.   
  13.         <LinearLayout  
  14.             android:id="@+id/linearlayout"  
  15.             android:layout_width="match_parent"  
  16.             android:layout_height="match_parent"  
  17.             android:orientation="vertical" >  
  18.   
  19.             <Button  
  20.                 android:layout_width="match_parent"  
  21.                 android:layout_height="67dp"  
  22.                 android:text="测试的item 01" />  
  23.   
  24.             <Button  
  25.                 android:layout_width="match_parent"  
  26.                 android:layout_height="67dp"  
  27.                 android:text="测试的item 02" />  
  28.   
  29.             <Button  
  30.                 android:layout_width="match_parent"  
  31.                 android:layout_height="67dp"  
  32.                 android:text="测试的item 03" />  
  33.   
  34.             <Button  
  35.                 android:layout_width="match_parent"  
  36.                 android:layout_height="67dp"  
  37.                 android:text="测试的item 04" />  
  38.   
  39.             <Button  
  40.                 android:layout_width="match_parent"  
  41.                 android:layout_height="67dp"  
  42.                 android:text="测试的item 05" />  
  43.   
  44.             <Button  
  45.                 android:layout_width="match_parent"  
  46.                 android:layout_height="67dp"  
  47.                 android:text="测试的item 06" />  
  48.   
  49.             <Button  
  50.                 android:layout_width="match_parent"  
  51.                 android:layout_height="67dp"  
  52.                 android:text="测试的item 07" />  
  53.   
  54.             <Button  
  55.                 android:layout_width="match_parent"  
  56.                 android:layout_height="67dp"  
  57.                 android:text="测试的item 08" />  
  58.   
  59.             <Button  
  60.                 android:layout_width="match_parent"  
  61.                 android:layout_height="67dp"  
  62.                 android:text="测试的item 09" />  
  63.   
  64.             <Button  
  65.                 android:layout_width="match_parent"  
  66.                 android:layout_height="67dp"  
  67.                 android:text="测试的item 10" />  
  68.         </LinearLayout>  
  69.     </ScrollView>  
  70.   
  71. </android.support.v4.widget.SwipeRefreshLayout>  


代码中使用:

[java] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. //findview  
  2. swipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.swipeRefreshLayout);  
  3. //设置卷内的颜色  
  4. swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright,  
  5.         android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light);  
  6. //设置下拉刷新监听  
  7. swipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() {  
  8.     @Override  
  9.     public void onRefresh() {  
  10.                 //.......操作  
  11.           
  12.                 //停止刷新动画  
  13.                 swipeRefreshLayout.setRefreshing(false);  
  14.     }  
  15. });  



Demo分享:

https://github.com/18236887539/SwipeRefreshLayout


最新的v7v4库:

http://download.csdn.net/detail/u011282069/8410899

0 0