這種加載效果我也看到過幾篇類似的博文,這里全當自己練習了。
效果如下:
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)