Android-设置PullToRefresh下拉刷新样式

来源:互联网 发布:主流建站软件 编辑:程序博客网 时间:2024/06/05 17:17

Android-设置PullToRefresh下拉刷新样式

以下是开源控件PullToRefresh的自定义样式属性:

[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <resources>  
  3.     <declare-styleable name="PullToRefresh">  
  4.         <!-- A drawable to use as the background of the Refreshable View -->  
  5.         <!-- 设置整个刷新列表的背景色 -->  
  6.         <attr name="ptrRefreshableViewBackground" format="reference|color" />  
  7.         <!-- A drawable to use as the background of the Header and Footer Loading Views -->  
  8.         <!--  设置下拉Header或者上拉Footer的背景色 -->  
  9.         <attr name="ptrHeaderBackground" format="reference|color" />  
  10.         <!-- Text Color of the Header and Footer Loading Views -->  
  11.         <!-- 用于设置Header与Footer中文本的颜色 -->  
  12.         <attr name="ptrHeaderTextColor" format="reference|color" />  
  13.         <!-- Text Color of the Header and Footer Loading Views Sub Header -->  
  14.         <!-- 用于设置Header与Footer中上次刷新时间的颜色 -->  
  15.         <attr name="ptrHeaderSubTextColor" format="reference|color" />  
  16.         <!-- Mode of Pull-to-Refresh that should be used -->  
  17.         <attr name="ptrMode">  
  18.             <flag name="disabled" value="0x0" /><!-- 禁用下拉刷新 -->  
  19.             <flag name="pullFromStart" value="0x1" /><!-- 仅支持下拉刷新 -->  
  20.             <flag name="pullFromEnd" value="0x2" /><!-- 仅支持上拉刷新 -->  
  21.             <flag name="both" value="0x3" /><!-- 上拉刷新和下拉刷新都支持 -->  
  22.             <flag name="manualOnly" value="0x4" /><!-- 只允许手动触发 -->  
  23.   
  24.             <!-- These last two are depreacted -->  
  25.             <flag name="pullDownFromTop" value="0x1" />  
  26.             <flag name="pullUpFromBottom" value="0x2" />  
  27.         </attr>  
  28.         <!-- Whether the Indicator overlay(s) should be used -->  
  29.         <!-- 如果为true会在mPullRefreshListView中出现icon,右上角和右下角,挺有意思的 -->  
  30.         <attr name="ptrShowIndicator" format="reference|boolean" />  
  31.         <!-- Drawable to use as Loading Indicator. Changes both Header and Footer. -->  
  32.         <!-- 同时改变头部和底部的图标 -->  
  33.         <attr name="ptrDrawable" format="reference" />  
  34.         <!-- Drawable to use as Loading Indicator in the Header View. Overrides value set in ptrDrawable. -->  
  35.         <!-- 头部视图的图标-->  
  36.         <attr name="ptrDrawableStart" format="reference" />  
  37.   
  38.         <!-- Drawable to use as Loading Indicator in the Footer View. Overrides value set in ptrDrawable. -->  
  39.         <!-- 底部视图的图标 -->  
  40.         <attr name="ptrDrawableEnd" format="reference" />  
  41.         <!-- Whether Android's built-in Over Scroll should be utilised for Pull-to-Refresh. -->  
  42.         <attr name="ptrOverScroll" format="reference|boolean" />  
  43.         <!-- Base text color, typeface, size, and style for Header and Footer Loading Views -->  
  44.          <!-- 分别设置拉Header或者上拉Footer中字体的类型颜色等等 -->  
  45.         <attr name="ptrHeaderTextAppearance" format="reference" />  
  46.         <!-- Base text color, typeface, size, and style for Header and Footer Loading Views Sub Header -->  
  47.         <attr name="ptrSubHeaderTextAppearance" format="reference" />  
  48.         <!-- Style of Animation should be used displayed when pulling. -->  
  49.         <attr name="ptrAnimationStyle">  
  50.             <flag name="rotate" value="0x0" /><!-- flip(翻转动画), rotate(旋转动画)  -->  
  51.             <flag name="flip" value="0x1" />  
  52.         </attr>  
  53.         <!-- Whether the user can scroll while the View is Refreshing -->  
  54.         <!-- 刷新的时候,是否允许ListView或GridView滚动 -->  
  55.         <attr name="ptrScrollingWhileRefreshingEnabled" format="reference|boolean" />  
  56.         <!--  
  57.             Whether PullToRefreshListView has it's extras enabled. This allows the user to be   
  58.             able to scroll while refreshing, and behaves better. It acheives this by adding  
  59.             Header and/or Footer Views to the ListView.  
  60.         -->  
  61.         <!-- 决定了Header,Footer以何种方式加入mPullRefreshListView,true为headView方式加入,就是滚动时刷新头部会一起滚动 -->  
  62.         <attr name="ptrListViewExtrasEnabled" format="reference|boolean" />  
  63.         <!--  
  64.             Whether the Drawable should be continually rotated as you pull. This only  
  65.             takes effect when using the 'Rotate' Animation Style.  
  66.         -->  
  67.         <attr name="ptrRotateDrawableWhilePulling" format="reference|boolean" />  
  68.         <!-- BELOW HERE ARE DEPRECEATED. DO NOT USE. -->  
  69.         <attr name="ptrAdapterViewBackground" format="reference|color" />  
  70.         <attr name="ptrDrawableTop" format="reference" />  
  71.         <attr name="ptrDrawableBottom" format="reference" />  
  72.     </declare-styleable>  
  73. </resources>  

可以在布局文件中设置自定义的这些样式,使用方法如下:

[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. <com.handmark.pulltorefresh.libaray        xmlns:ptr="http://schemas.android.com/apk/res-auto"  
  2.         android:id="@+id/lv"  
  3.         android:layout_width="match_parent"  
  4.         android:layout_height="match_parent"  
  5.         android:background="@color/white"  
  6.         android:cacheColorHint="#00000000"  
  7.         android:divider="@drawable/border"  
  8.         android:fadingEdge="none"  
  9.         android:fadingEdgeLength="0dip"  
  10.         android:scrollbars="none"  
  11.         android:scrollingCache="true"   
  12.         ptr:ptrDrawable="@drawable/infzm_logo"  
  13.      />  

注意:需要声明命名空间:xmlns:ptr=http://schemas.android.com/apk/res-auto

使用自定义属性:ptr:ptrDrawable="@drawable/logo"

其他属性使用方法类似。

Android-设置PullToRefresh下拉刷新样式

以下是开源控件PullToRefresh的自定义样式属性:

[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <resources>  
  3.     <declare-styleable name="PullToRefresh">  
  4.         <!-- A drawable to use as the background of the Refreshable View -->  
  5.         <!-- 设置整个刷新列表的背景色 -->  
  6.         <attr name="ptrRefreshableViewBackground" format="reference|color" />  
  7.         <!-- A drawable to use as the background of the Header and Footer Loading Views -->  
  8.         <!--  设置下拉Header或者上拉Footer的背景色 -->  
  9.         <attr name="ptrHeaderBackground" format="reference|color" />  
  10.         <!-- Text Color of the Header and Footer Loading Views -->  
  11.         <!-- 用于设置Header与Footer中文本的颜色 -->  
  12.         <attr name="ptrHeaderTextColor" format="reference|color" />  
  13.         <!-- Text Color of the Header and Footer Loading Views Sub Header -->  
  14.         <!-- 用于设置Header与Footer中上次刷新时间的颜色 -->  
  15.         <attr name="ptrHeaderSubTextColor" format="reference|color" />  
  16.         <!-- Mode of Pull-to-Refresh that should be used -->  
  17.         <attr name="ptrMode">  
  18.             <flag name="disabled" value="0x0" /><!-- 禁用下拉刷新 -->  
  19.             <flag name="pullFromStart" value="0x1" /><!-- 仅支持下拉刷新 -->  
  20.             <flag name="pullFromEnd" value="0x2" /><!-- 仅支持上拉刷新 -->  
  21.             <flag name="both" value="0x3" /><!-- 上拉刷新和下拉刷新都支持 -->  
  22.             <flag name="manualOnly" value="0x4" /><!-- 只允许手动触发 -->  
  23.   
  24.             <!-- These last two are depreacted -->  
  25.             <flag name="pullDownFromTop" value="0x1" />  
  26.             <flag name="pullUpFromBottom" value="0x2" />  
  27.         </attr>  
  28.         <!-- Whether the Indicator overlay(s) should be used -->  
  29.         <!-- 如果为true会在mPullRefreshListView中出现icon,右上角和右下角,挺有意思的 -->  
  30.         <attr name="ptrShowIndicator" format="reference|boolean" />  
  31.         <!-- Drawable to use as Loading Indicator. Changes both Header and Footer. -->  
  32.         <!-- 同时改变头部和底部的图标 -->  
  33.         <attr name="ptrDrawable" format="reference" />  
  34.         <!-- Drawable to use as Loading Indicator in the Header View. Overrides value set in ptrDrawable. -->  
  35.         <!-- 头部视图的图标-->  
  36.         <attr name="ptrDrawableStart" format="reference" />  
  37.   
  38.         <!-- Drawable to use as Loading Indicator in the Footer View. Overrides value set in ptrDrawable. -->  
  39.         <!-- 底部视图的图标 -->  
  40.         <attr name="ptrDrawableEnd" format="reference" />  
  41.         <!-- Whether Android's built-in Over Scroll should be utilised for Pull-to-Refresh. -->  
  42.         <attr name="ptrOverScroll" format="reference|boolean" />  
  43.         <!-- Base text color, typeface, size, and style for Header and Footer Loading Views -->  
  44.          <!-- 分别设置拉Header或者上拉Footer中字体的类型颜色等等 -->  
  45.         <attr name="ptrHeaderTextAppearance" format="reference" />  
  46.         <!-- Base text color, typeface, size, and style for Header and Footer Loading Views Sub Header -->  
  47.         <attr name="ptrSubHeaderTextAppearance" format="reference" />  
  48.         <!-- Style of Animation should be used displayed when pulling. -->  
  49.         <attr name="ptrAnimationStyle">  
  50.             <flag name="rotate" value="0x0" /><!-- flip(翻转动画), rotate(旋转动画)  -->  
  51.             <flag name="flip" value="0x1" />  
  52.         </attr>  
  53.         <!-- Whether the user can scroll while the View is Refreshing -->  
  54.         <!-- 刷新的时候,是否允许ListView或GridView滚动 -->  
  55.         <attr name="ptrScrollingWhileRefreshingEnabled" format="reference|boolean" />  
  56.         <!--  
  57.             Whether PullToRefreshListView has it's extras enabled. This allows the user to be   
  58.             able to scroll while refreshing, and behaves better. It acheives this by adding  
  59.             Header and/or Footer Views to the ListView.  
  60.         -->  
  61.         <!-- 决定了Header,Footer以何种方式加入mPullRefreshListView,true为headView方式加入,就是滚动时刷新头部会一起滚动 -->  
  62.         <attr name="ptrListViewExtrasEnabled" format="reference|boolean" />  
  63.         <!--  
  64.             Whether the Drawable should be continually rotated as you pull. This only  
  65.             takes effect when using the 'Rotate' Animation Style.  
  66.         -->  
  67.         <attr name="ptrRotateDrawableWhilePulling" format="reference|boolean" />  
  68.         <!-- BELOW HERE ARE DEPRECEATED. DO NOT USE. -->  
  69.         <attr name="ptrAdapterViewBackground" format="reference|color" />  
  70.         <attr name="ptrDrawableTop" format="reference" />  
  71.         <attr name="ptrDrawableBottom" format="reference" />  
  72.     </declare-styleable>  
  73. </resources>  

可以在布局文件中设置自定义的这些样式,使用方法如下:

[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. <com.handmark.pulltorefresh.libaray        xmlns:ptr="http://schemas.android.com/apk/res-auto"  
  2.         android:id="@+id/lv"  
  3.         android:layout_width="match_parent"  
  4.         android:layout_height="match_parent"  
  5.         android:background="@color/white"  
  6.         android:cacheColorHint="#00000000"  
  7.         android:divider="@drawable/border"  
  8.         android:fadingEdge="none"  
  9.         android:fadingEdgeLength="0dip"  
  10.         android:scrollbars="none"  
  11.         android:scrollingCache="true"   
  12.         ptr:ptrDrawable="@drawable/infzm_logo"  
  13.      />  

注意:需要声明命名空间:xmlns:ptr=http://schemas.android.com/apk/res-auto

使用自定义属性:ptr:ptrDrawable="@drawable/logo"

其他属性使用方法类似。

0 0