Android-设置PullToRefresh下拉刷新样式

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

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <declare-styleable name="PullToRefresh">
    <!-- A drawable to use as the background of the Refreshable View -->
    <!-- 设置整个刷新列表的背景色 -->
    <attr name="ptrRefreshableViewBackground" format="reference|color" />
    <!-- A drawable to use as the background of the Header and Footer Loading Views -->
    <!--  设置下拉Header或者上拉Footer的背景色 -->
    <attr name="ptrHeaderBackground" format="reference|color" />
    <!-- Text Color of the Header and Footer Loading Views -->
    <!-- 用于设置Header与Footer中文本的颜色 -->
    <attr name="ptrHeaderTextColor" format="reference|color" />
    <!-- Text Color of the Header and Footer Loading Views Sub Header -->
    <!-- 用于设置Header与Footer中上次刷新时间的颜色 -->
    <attr name="ptrHeaderSubTextColor" format="reference|color" />
    <!-- Mode of Pull-to-Refresh that should be used -->
    <attr name="ptrMode">
      <flag name="disabled" value="0x0" /><!-- 禁用下拉刷新 -->
      <flag name="pullFromStart" value="0x1" /><!-- 仅支持下拉刷新 -->
      <flag name="pullFromEnd" value="0x2" /><!-- 仅支持上拉刷新 -->
      <flag name="both" value="0x3" /><!-- 上拉刷新和下拉刷新都支持 -->
      <flag name="manualOnly" value="0x4" /><!-- 只允许手动触发 -->

      <!-- These last two are depreacted -->
      <flag name="pullDownFromTop" value="0x1" />
      <flag name="pullUpFromBottom" value="0x2" />
    </attr>
    <!-- Whether the Indicator overlay(s) should be used -->
    <!-- 如果为true会在mPullRefreshListView中出现icon,右上角和右下角,挺有意思的 -->
    <attr name="ptrShowIndicator" format="reference|boolean" />
    <!-- Drawable to use as Loading Indicator. Changes both Header and Footer. -->
    <!-- 同时改变头部和底部的图标 -->
    <attr name="ptrDrawable" format="reference" />
    <!-- Drawable to use as Loading Indicator in the Header View. Overrides value set in ptrDrawable. -->
    <!-- 头部视图的图标-->
    <attr name="ptrDrawableStart" format="reference" />

    <!-- Drawable to use as Loading Indicator in the Footer View. Overrides value set in ptrDrawable. -->
    <!-- 底部视图的图标 -->
    <attr name="ptrDrawableEnd" format="reference" />
    <!-- Whether Android‘s built-in Over Scroll should be utilised for Pull-to-Refresh. -->
    <attr name="ptrOverScroll" format="reference|boolean" />
    <!-- Base text color, typeface, size, and style for Header and Footer Loading Views -->
     <!-- 分别设置拉Header或者上拉Footer中字体的类型颜色等等 -->
    <attr name="ptrHeaderTextAppearance" format="reference" />
    <!-- Base text color, typeface, size, and style for Header and Footer Loading Views Sub Header -->
    <attr name="ptrSubHeaderTextAppearance" format="reference" />
    <!-- Style of Animation should be used displayed when pulling. -->
    <attr name="ptrAnimationStyle">
      <flag name="rotate" value="0x0" /><!-- flip(翻转动画), rotate(旋转动画)  -->
      <flag name="flip" value="0x1" />
    </attr>
    <!-- Whether the user can scroll while the View is Refreshing -->
    <!-- 刷新的时候,是否允许ListView或GridView滚动 -->
    <attr name="ptrScrollingWhileRefreshingEnabled" format="reference|boolean" />
    <!--
      Whether PullToRefreshListView has it‘s extras enabled. This allows the user to be
      able to scroll while refreshing, and behaves better. It acheives this by adding
      Header and/or Footer Views to the ListView.
    -->
    <!-- 决定了Header,Footer以何种方式加入mPullRefreshListView,true为headView方式加入,就是滚动时刷新头部会一起滚动 -->
    <attr name="ptrListViewExtrasEnabled" format="reference|boolean" />
    <!--
      Whether the Drawable should be continually rotated as you pull. This only
      takes effect when using the ‘Rotate‘ Animation Style.
    -->
    <attr name="ptrRotateDrawableWhilePulling" format="reference|boolean" />
    <!-- BELOW HERE ARE DEPRECEATED. DO NOT USE. -->
    <attr name="ptrAdapterViewBackground" format="reference|color" />
    <attr name="ptrDrawableTop" format="reference" />
    <attr name="ptrDrawableBottom" format="reference" />
  </declare-styleable>
</resources>

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

<com.handmark.pulltorefresh.libaray.PullToRefreshListView          xmlns:ptr="http://schemas.android.com/apk/res-auto"
  android:id="@+id/lv"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="@color/white"
  android:cacheColorHint="#00000000"
  android:divider="@drawable/border"
  android:fadingEdge="none"
  android:fadingEdgeLength="0dip"
  android:scrollbars="none"
  android:scrollingCache="true"
  ptr:ptrDrawable="@drawable/infzm_logo"
 />

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

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

其他属性使用方法类似。

时间: 2024-08-25 21:54:25

Android-设置PullToRefresh下拉刷新样式的相关文章

Android PullToRefresh 下拉刷新,上拉很多其它,支持ScrollView,ListView,可方便拓展GridView,WebView等

在写着东西之前.从网上找到非常多这方面的源代码,可是基本没有找到惬意的.包含在GitHub上的比較有名的Android-PullToRefresh-master.思来想去还是自己写吧.当然当中借鉴了一些别的开源代码! 废话不多说,直接上代码.凝视非常全乎,应该不难理解,Demo下载地址在最后: package com.zs.pulltorefreshtest; import android.content.Context; import android.util.AttributeSet; im

Android PullToRefresh 下拉刷新,上拉更多,支持ScrollView,ListView,可方便拓展GridView,WebView等

在写着东西之前,从网上找到很多这方面的源码,但是基本没有找到满意的,包括在GitHub上的比较有名的Android-PullToRefresh-master,思来想去还是自己写吧,当然其中借鉴了一些别的开源代码! 废话不多说,直接上代码,注释很全乎,应该不难理解,Demo下载地址在最后: package com.zs.pulltorefreshtest; import android.content.Context; import android.util.AttributeSet; impor

.Net 转战 Android 4.4 日常笔记(10)--PullToRefresh下拉刷新使用

下拉刷新很多地方都用到了,新浪微博,微信,百度新闻 这里我们使用一个开源的库叫:PullToRefresh 开源地址:https://github.com/chenyoca/pull-to-refresh 下载地址:https://github.com/chenyoca/pull-to-refresh/archive/master.zip 解压代码之后通过ecplise导入到项目里面 导入之后可能会出现库路径引用错误 在项目右键,依次对库进行修正 运行主Activity 这时就可以看到效果了!接

android控件 下拉刷新pulltorefresh

外国人写的下拉刷新控件,我把他下载下来放在网盘,有时候访问不了github 支持各种控件下拉刷新 ListView.ViewPager.WevView.ExpandableListView.GridView.(Horizontal )ScrollView.Fragment上下左右拉动刷新,比下面johannilsson那个只支持ListView的强大的多.并且他实现的下拉刷新ListView在item不足一屏情况下也不会显示刷新提示,体验更好. 国内网盘地址:http://www.400gb.c

Android UI- PullToRrefresh自定义下拉刷新动画

Android UI- PullToRrefresh自定义下拉刷新动画 如果觉得本文不错,麻烦投一票,2014年博客之星投票地址:http://vote.blog.csdn.net/blogstar2014/details?username=wwj_748#content 本篇博文要给大家分享的是如何使用修改开源项目PullToRrefresh下拉刷新的动画,来满足我们开发当中特定的需求,我们比较常见的一种下拉刷新样式可能是以下这种: 就是下拉列表的时候两个箭头上下翻转,更改日期文本和刷新状态,

Android中实现下拉刷新

需求:项目中的消息列表界面要求实现类似sina微博的下拉刷新: 思路:一般的消息列表为ListView类型,将list加载到adapter中,再将adapter加载到 ListView中,从而实现消息列表的展示.而下拉刷新要求给消息列表加一个头部,其中有图片(向上/向下箭头)和提示字样(下拉刷新/松开刷新),从 而我们需要做的事情:1.需要做一个head.xm来实现头部的样式定义:2.需要自定义一个继承了ListView的MsgListView,在该类中 将head加在MsgListView对象

Android自定义ListView下拉刷新

实现的目标是本地有数据并没有刷新.下拉数据及时刷新数据. 我在网上找了某位写的MyListView,这个东西的下拉核心部分还是没有弄明白.非常感谢这位作者. XML布局文件源代码: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layou

Android PullToRefresh下拉刷新控件的简单使用

PullToRefresh这个开源库早就听说了,不过一直没用过.作为一个经典的的开源库,我觉得还是有必要认识一下. 打开github上的网址:https://github.com/chrisbanes/Android-PullToRefresh 网页一打开就看到一个大大的提醒(说是该项目已经不再维护了): 不管怎样先下载下来再说: 下载解压后,打开文件夹如下图所示: 然后导入到工程,如下图所示:(其中的PullToRefreshListFragment和PullToRefreshViewPage

Android StaggeredGrid 加下拉刷新功能 PullToRefresh

https://github.com/etsy/AndroidStaggeredGrid  用的github上面提供瀑布流,继承于abslistview,回收机制不错,并且提供了OnScrollListener来监听滑动时间. 然后想加一个下拉刷新功能,下面分享一下研究的最终结果. Java代码: package com.xxx.waterfall; import android.annotation.TargetApi; import android.content.Context; impo