關(guān)鍵字:沒有關(guān)鍵字
項(xiàng)目地址:AboutMaterialDesign
說明:其實(shí)和 Material Design 沒關(guān)系,API 11 以上就可以完美使用,一點(diǎn)不帶卡頓
效果展示
一、從官網(wǎng)說起
Return Type | Desciption |
---|---|
Object | evaluate(float fraction, Object startValue, Object endValue) |
沒了。
不如還是來看看怎么用吧。
二、簡(jiǎn)單使用,并沒有高級(jí)
先看這個(gè)唯一的方法的方法介紹:
This function returns the calculated in-between value for a color given integers that represent the start and end values in the four bytes of the 32-bit int.
簡(jiǎn)單的說,startValue 和 endValue 是兩個(gè) Integer 類型的 Color 值,fraction 在 0 -1 之間,方法能通過這個(gè)值返回兩個(gè)顏色之間的過渡色,想達(dá)到上面的漸變效果,只要在一定時(shí)間間隔,計(jì)算出漸變色彩并分別賦值給背景就可以了。
開篇的效果是利用 ViewPager 的監(jiān)聽做的,監(jiān)聽中會(huì)返回指定的 positionOffset 值,如下:
private class PagerChangeListener implements ViewPager.OnPageChangeListener{
private int[] colors = {Color.parseColor("#e16428"),Color.parseColor("#ffbc2c"),
Color.parseColor("#86b86b"),Color.parseColor("#878ecd"),Color.parseColor("#9a9b94"),};
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
if (positionOffset == 0) {
return;
}
//得到 顏色 估值器
ArgbEvaluator evaluator = new ArgbEvaluator();
//根據(jù)positionOffset得到漸變色
int evaluate = (int) evaluator.evaluate(positionOffset,colors[position],colors[position+1]);
mContainer.setBackgroundColor(evaluate);
}
//...some other method
}
如果是一般的 View 則需要自己進(jìn)行計(jì)算了,例如利用 CountDownTimer 定時(shí)賦值。
謝謝觀賞