一般情況下,我試圖動畫int類型的數組,不像典型的情況下,你只是一個動畫int或從一個號碼浮到另一個。動畫兩個值同步在Android
具體來說,我試圖在GradientDrawable對象上設置顏色的int []。
GradientDrawable具有指定屬性「setColors(INT [])」,其中我設置2種顏色,起始色和終了色,從而彌補了一個整體梯度。
我想從一種顏色組合向另一種顏色組合。如果是純色的,我已經能夠做到這一點,如下所示:
Integer colorFrom = getResources().getColor(R.color.red);
Integer colorTo = getResources().getColor(R.color.blue);
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
colorAnimation.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animator) {
textView.setBackgroundColor((Integer)animator.getAnimatedValue());
}
});
colorAnimation.start();
所以,我需要這樣的:
//Define 2 starting colors
Integer colorFrom1 = getResources().getColor(R.color.red);
Integer colorFrom2 = getResources().getColor(R.color.darkred);
int[] startColors = new int[] {colorFrom1, colorFrom2};
//Define 2 ending colors
Integer colorTo1 = getResources().getColor(R.color.blue);
Integer colorTo2 = getResources().getColor(R.color.darkblue);
int[] endColors = new int[] {colorTo1, colorTo2};
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), startColors, endColors);
colorAnimation.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animator) {
gradientView.setColors((Integer)animator.getAnimatedValues()[0] , (Integer)animator.getAnimatedValues()[1]);
}
});
colorAnimation.start();
Obvioulsy將不存在的代碼,因爲沒有getAnimatedValues()方法返回一個數組,並且沒有ValueAnimator.ofObject方法接受一個數組作爲開始和結束值。
任何想法?
我現在唯一的想法是並行運行兩個動畫師,每個動畫漸變的一個維度,每個設置只有一半的數組接受gradientDrawable.setColors()....但boyyyy幾乎無法接受效率低下並且可能危險地失去同步。