模仿饿了么加载效果(五八同城,UC也都有这个效果)

这种加载效果我也看到过几篇类似的博文,这里全当自己练习了。
效果如下:
github地址:https://github.com/niniloveyou/BounceLoadingView (欢迎star)

bounceLoadingView.gif

其实很简单,首先说需要提供几个方法添加图片

addBitmap(bitmap)
addBitmap(resId)
addBitmaps(mBitmapList)

然后new 一个无限循环的ValueAnimator ,在数值不断变化的时候不断postInvalide(); 画下面的椭圆和bitmap

valueAnimator的时长即一个bitmap弹起落下的时间, 这就是一个周期。
在一个周期结束后更换图片,也就是:

animator.addListener(new AnimatorListenerAdapter() {    
    @Override    
     public void onAnimationStart(Animator animation) {       
     //重置index        
      mCurrentIndex = 0;       
      mCurrentBitmap = mBitmapList.get(mCurrentIndex);    
  }    
    @Override    
    public void onAnimationRepeat(Animator animation) {        
         if(mBitmapList != null && mBitmapList.size() > 0){            
            mCurrentIndex ++;            
            if(mCurrentIndex >= mBitmapList.size()) {                
                 mCurrentIndex = 0;            
            }            
            mCurrentBitmap = mBitmapList.get(mCurrentIndex);       
        }    
   }});

详细的代码在这里:
github地址:https://github.com/niniloveyou/BounceLoadingView (欢迎star)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容