Android-设置PullToRefresh下拉刷新样式

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        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"

其他属性使用方法类似。



  • 14
    点赞
  • 43
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小巫技术博客

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值