使用:
loadingView.addBitmap(R.mipmap.v4);
or
loadingView.addBitmap(bitmap);
or
loadingView.addBitmaps(mBitmapList);
//set the shadow color
loadingView.setShadowColor(Color.LTGRAY);
//set the duration of animation
loadingView.setDuration(800);
loadingView.start();
原理:
其實很簡單,首先說需要提供幾個方法添加圖片
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);
}
}});