模仿餓了么加載效果(五八同城,UC也都有這個效果)

這種加載效果我也看到過幾篇類似的博文,這里全當自己練習了。
效果如下:
github地址:https://github.com/niniloveyou/BounceLoadingView (歡迎star)

bounceLoadingView.gif

其實很簡單,首先說需要提供幾個方法添加圖片

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

然后new 一個無限循環(huán)的ValueAnimator ,在數(shù)值不斷變化的時候不斷postInvalide(); 畫下面的橢圓和bitmap

valueAnimator的時長即一個bitmap彈起落下的時間, 這就是一個周期。
在一個周期結(jié)束后更換圖片,也就是:

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)

最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容