Android仿京东,天猫下拉刷新效果

  

说到下拉刷新,相信大家都不陌生,现在基本上每个项目都会用的到。我们公司的项目一直都是使用SwipeRefreshLayout,官方的材料设计风格,好用少错误。现在下拉刷新大概有下面几种实现方式:一种是直接包在列表视图或者RecyclerView的头部,有的则是像SwipeRefreshLayout一样,包在视图的最外层,个人建议使用包在最外层的做法,可拓展性比较强。下面用包在最外层的方法实现京东和天猫的下拉刷新。
  

  

<强> 1。使用框架Android-Ultra-Pull-To-Refresh
  

  

https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh
  

  

大家有兴趣的可以去看一下这个下拉刷新框架,可拓展性非常强,兼容各种视图的下拉刷新事件。
  

  

<强> 2。京东下拉刷新
  

  

先看看京东的下拉刷新动画:

  

 Android仿京东,天猫下拉刷新效果

  

从上图可以看的出,就是一个动画,当然截图有点卡,首先,我们解压手机京东的应用,得到上面的图片:

  

 Android仿京东,天猫下拉刷新效果

  

先看看头部刷新的布局怎么实现:
  jd_refresh_header_view。xml
  

        & lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比;   & lt;使用   xmlns: android=" http://schemas.android.com/apk/res/android "   android: layout_width=" match_parent "   android: layout_height=皐rap_content”比;      & lt; FrameLayout   android: layout_width=" wrap_content "   android: layout_height=" wrap_content "   android: layout_toLeftOf=癅 + id/layout_tx”比;      & lt; ImageView   android: id=癅 + id/iv_man”   android: layout_width=" wrap_content "   android: layout_height=" wrap_content "   android:背景=癅drawable/负责/比;      & lt; ImageView   android: id=癅 + id/iv_goods”   android: layout_width=" wrap_content "   android: layout_height=" wrap_content "   android: layout_gravity="权利|中心”   android: src=" https://www.yisu.com/zixun/@drawable a29 "/比;   & lt;/FrameLayout>      LinearLayout & lt;   android: id=癅 + id/layout_tx”   android: layout_width=" wrap_content "   android: layout_height=" wrap_content "   android: layout_centerInParent=" true "   android: layout_marginLeft=" 5 dp "   android:重力=" center_vertical "   android:取向=按怪薄?   android:填充=" 5 dp "比;      & lt; TextView   android: layout_width=" wrap_content "   android: layout_height=" wrap_content "   android:文本="让购物更便捷”   android: textSize=" 14 sp "/比;      & lt; TextView   android: id=癅 + id/tv_remain”   android: layout_width=" wrap_content "   android: layout_height=" wrap_content "   android: layout_marginTop=" 5 dp "   android:文本="松开刷新”   android: textSize=" 12 sp "/比;   & lt;/LinearLayout>   & lt;/RelativeLayout>         之前      

咱们再看看android-Ultra-Pull-To-Refresh这个框架:
  

        包in.srain.cube.views.ptr;      进口in.srain.cube.views.ptr.indicator.PtrIndicator;/* *   *   */公共接口PtrUIHandler {/* *   *当内容视图已达到顶部和更新已经完成,视图将被重新设置。   *   * @param框架   */公共空间>   包com.jackie.pulltorefresh.jd;      进口android.content.Context;   进口android.graphics.drawable.AnimationDrawable;   进口android.util.AttributeSet;   进口android.view.LayoutInflater;   进口android.view.View;   进口android.widget.FrameLayout;   进口android.widget.ImageView;   进口android.widget.TextView;      进口com.jackie.pulltorefresh.R;      进口in.srain.cube.views.ptr.PtrFrameLayout;   进口in.srain.cube.views.ptr.PtrUIHandler;   进口in.srain.cube.views.ptr.indicator.PtrIndicator;/* *   *下拉刷新HeaderView   */公共类JdRefreshHeader FrameLayout延伸实现PtrUIHandler {/* *   *提醒文本   */私人TextView mTvRemind;/* *   *快递员的标志   */私人ImageView mIvMan;/* *   *商品标志   */私人ImageView mIvGoods;/* *   *状态识别   */私人int mState;/* *   *重置   *准备刷新   *开始刷新   *结束刷新   */公共静态最终int STATE_RESET=1;   公共静态最终int STATE_PREPARE=0;   公共静态最终int STATE_BEGIN=1;   公共静态最终int STATE_FINISH=2;      公共静态最终int MARGIN_RIGHT=100;/* *   *动画   */私人AnimationDrawable mAnimationDrawable;         公共JdRefreshHeader(上下文语境){   这(上下文,null);   }      公共JdRefreshHeader(上下文语境,AttributeSet attrs) {   这(上下文、attrs 0);   }      公共JdRefreshHeader(上下文语境、AttributeSet attrs int defStyleAttr) {   超级(上下文、attrs defStyleAttr);      initView ();   }/* *   *初始化视图   */私人空间initView () {   视图视图=LayoutInflater.from (getContext ()) .inflate (R.layout.jd_refresh_header_view,假);   mTvRemind=(TextView) view.findViewById (R.id.tv_remain);   mIvMan=(ImageView) view.findViewById (R.id.iv_man);   mIvGoods=(ImageView) view.findViewById (R.id.iv_goods);   addView(查看);   }         @Override   公共空间>   & lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比;   & lt; animation-list xmlns: android=" http://schemas.android.com/apk/res/android " android:一次通过=癴alse”比;   & lt;项目   android:可拉的=" @drawable/a2b”   android:=" 70 "/持续时间比;   & lt;项目   android:可拉的=" @drawable/a2c”   android:=" 70 "/持续时间比;   & lt;项目   android:可拉的=" @drawable/a2d”   android:=" 70 "/持续时间比;   & lt;/animation-list>   

Android仿京东,天猫下拉刷新效果