• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >Android > 深度剖析:Android_PullToRefresh

深度剖析:Android_PullToRefresh

作者:网友 字体:[增加 减小] 来源:互联网 时间:2017-05-26

网友通过本文主要向大家介绍了web安全深度剖析,深度剖析,libevent源码深度剖析,c语言深度剖析,web安全深度剖析pdf等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

深度剖析:Android_PullToRefresh


上拉加载更多,下拉刷新,网上比较强大比较全的一个开源库PullToRefresh,支持Listview、GridView、ScrollView等众多控件。下载地址:

git clone https://github.com/chrisbanes/Android-PullToRefresh.git

噢,伙计,当然你也可以这样

https://github.com/chrisbanes/Android-PullToRefresh

源码剖析

整个库先从地基入手PullToRefreshBase,我们必须先了解这个类关联的类别,先看State枚举类

public static enum State {

        /**
         * When the UI is in a state which means that user is not interacting
         * with the Pull-to-Refresh function.
         * 重置初始化状态
         */
        RESET(0x0),

        /**
         * When the UI is being pulled by the user, but has not been pulled far
         * enough so that it refreshes when released.
         * 拉动距离不足指定阈值,进行释放
         */
        PULL_TO_REFRESH(0x1),

        /**
         * When the UI is being pulled by the user, and has
         * been pulled far enough so that it will refresh when released.
         * 拉动距离大于等于指定阈值,进行释放
         */
        RELEASE_TO_REFRESH(0x2),

        /**
         * When the UI is currently refreshing, caused by a pull gesture.
         * 由于用户手势操作,引起当前UI刷新
         */
        REFRESHING(0x8),

        /**
         * When the UI is currently refreshing, caused by a call to
         * {@link PullToRefreshBase#setRefreshing() setRefreshing()}.
         * 由于代码调用setRefreshing引起刷新UI
         */
        MANUAL_REFRESHING(0x9),

        /**
         * When the UI is currently overscrolling, caused by a fling on the
         * Refreshable View.
         * 由于结束滑动,可以刷新视图
         */
        OVERSCROLLING(0x10);

        /**
         * Maps an int to a specific state. This is needed when saving state.
         * int 映射到状态,需要保存这个状态,直白的说:根据index 获取枚举类型
         * @param stateInt - int to map a State to
         * @return State that stateInt maps to
         */
        static State mapIntToValue(final int stateInt) {
            for (State value : State.values()) {
                if (stateInt == value.getIntValue()) {
                    return value;
                }
            }

            // If not, return default
            return RESET;
        }

        private int mIntValue;

        State(int intValue) {
            mIntValue = intValue;
        }

        int getIntValue() {
            return mIntValue;
        }
    }

再来看Mode的枚举类

public static enum Mode {

        /**
         * Disable all Pull-to-Refresh gesture and Refreshing handling
         * 禁用刷新加载
         */
        DISABLED(0x0),

        /**
         * Only allow the user to Pull from the start of the Refreshable View to
         * refresh. The start is either the Top or Left, depending on the
         * scrolling direction.
         * 仅仅支持下动刷新
         */
        PULL_FROM_START(0x1),

        /**
         * Only allow the user to Pull from the end of the Refreshable View to
         * refresh. The start is either the Bottom or Right, depending on the
         * scrolling direction.
         * 仅仅支持上啦加载更多
         */
        PULL_FROM_END(0x2),

        /**
         * Allow the user to both Pull from the start, from the end to refresh.
         * 上啦下拉都支持
         */
        BOTH(0x3),

        /**
         * Disables Pull-to-Refresh gesture handling, but allows manually
         * setting the Refresh state via
         * {@link PullToRefreshBase#setRefreshing() setRefreshing()}.
         * 只允许手动触发
         */
        MANUAL_REFRESH_ONLY(0x4);

        /**
         * @deprecated Use {@link #PULL_FROM_START} from now on.
         * 不赞成使用,过时了
         */
        public static Mode PULL_DOWN_TO_REFRESH = Mode.PULL_FROM_START;

        /**
         * @deprecated Use {@link #PULL_FROM_END} from now on.
         */
        public static Mode PULL_UP_TO_REFRESH = Mode.PULL_FROM_END;

        /**
         * Maps an int to a specific mode. This is needed when saving state, or
         * inflating the view from XML where the mode is given through a attr
         * int.
         * 
         * @param modeInt - int to map a Mode to
         * @return Mode that modeInt maps to, or PULL_FROM_START by default.
         */
        static Mode mapIntToValue(final int modeInt) {
            for (Mode value : Mode.values()) {
                if (modeInt == value.getIntValue()) {
                    return value;
                }
            }

            // If not, return default
            return getDefault();
        }
        //默认状态只支持刷新 
        static Mode getDefault() {
            return PULL_FROM_START;
        }

        private int mIntValue;

        // The modeInt values need to match those from attrs.xml
        //mode的值要与自定义属性的值相匹配
        Mode(int modeInt) {
            mIntValue = modeInt;
        }

        /**
         * @return true if the mode permits Pull-to-Refresh
         * 如果当前模式允许刷新则返回true
         */
        boolean permitsPullToRefresh() {
            return !(this == DISABLED || this == MANUAL_REFRESH_ONLY);
        }

        /**
         * @return true if this mode wants the Loading Layout Header to be shown
         * 如果该模式下能加载显示header部分,则返回true
         */
        public boolean showHeaderLoadingLayout() {
            return this == PULL_FROM_START || this == BOTH;
        }

        /**
         * @return true if this mode wants the Loading Layout Footer to be shown
         * 如果该模式下能加载显示footer部分,则返回true
         */
        public boolean showFooterLoadingLayout() {
            return this == PULL_FROM_END || this == BOTH || this == MANUAL_REFRESH_ONLY;
        }

        int getIntValue() {
            return mIntValue;
        }

    }

动画相关枚举类型AnimationStyle

public static enum AnimationStyle {
        /**
         * This is the default for Android-PullToRefresh. Allows you to use any
         * drawable, which is automatically rotated and used as a Progress Bar.
         * 默认使用旋转的进度条 ProgressBar
         */
        ROTATE,

        /**
         * This is the old default, and what is commonly used on iOS. Uses an
         * arrow image which flips depending on where the user has scrolled.
         * 箭头图像翻转根据用户手势
         */
        FLIP;

        static AnimationStyle getDefault() {
            return ROTATE;
        }

        /**
         * Maps an int to a specific mode. This is needed when saving state, or
         * inflating the view from XML where the mode is given through a attr
         * int.
         * 
         * @param modeInt - int to map a Mode to
         * @return Mode that modeInt maps to, or ROTATE by default.
         */
        static AnimationStyle mapIntToValue(int modeInt) {
            switch (modeInt) {
                case 0x0:
                default:
                    return ROTATE;
                case 0x1:
                    return FLIP;
            }
        }

        LoadingLayout createLoadingLayout(Context context, Mode mode, Orientation scrollDirection, TypedArray attrs) {
            switch (this) {
                case ROTATE:
                default:
                    return new RotateLoadingLayout(context, mode, scrollDirection, attrs);
                case FLIP:
                    return new FlipLoadingLayout(context, mode, scrollDirection, attrs);
            }
        }
    }

分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • 深度剖析:Android_PullToRefresh

相关文章

  • 2017-05-26Android开发日常-listVIiew嵌套webView回显阅读位置,-listviiewwebview
  • 2017-05-26Android 接入 OpenCV库的三种方式,androidopencv
  • 2017-05-26android 之 启动画面的两种方法,android两种方法
  • 2017-05-26Java入门(二)——果然断更的都是要受惩罚的。。。,java受惩罚
  • 2017-05-26二维码Zxing&Zbar,zxing
  • 2017-05-26Android动画原理总结
  • 2017-05-26贝塞尔曲线实现的购物车添加商品动画效果,贝塞尔购物车
  • 2017-05-26Android 面试题总结(二)
  • 2017-05-26AndroidStudio项目打包成jar,androidstudiojar
  • 2017-05-26Android提权漏洞CVE-2014-7920&CVE-2014-7921分析

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • Android学习笔记(28):三种选择器DatePicker_TimePicker_NumberPicker剖析
    • Android简单的ListViewDemo及每个控件的点击事件,listview控件点击事件
    • Android触摸事件(三)-触摸事件类使用实例
    • Android消息机制Handler解析(源码+Demo)
    • Neo4j入门点滴(一):Cypher
    • Android Activity的生命周期简单总结
    • andriod 获取电池的信息,andriod获取电池
    • 手机影音10--音乐列表,影音10--列表
    • Android开发6:Service的使用(简单音乐播放器的实现),androidservice
    • Android Call(打电话)的基本知识详解,androidcall

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有