仿餓了麼加載動畫

餓了麼
使用:

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);       

}    

}});

demo下載http://download.csdn.net/detail/qq_35549248/9846425

發佈了47 篇原創文章 · 獲贊 55 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章