I'm trying to create smooth color animation in my WaveView. Unfortunatelly animation is creating rainbow effect spamming through every color from start to end.
I'll need it to go from Red to Green with just (Red -> Orange - > Yellow - > Greenish -> Green) like on RGB tables.
Here's my ObjectAnimator:
ObjectAnimator waveColor = ObjectAnimator.ofInt(
mWaveView, "waveColor",Color.parseColor("#64ff0000"),Color.parseColor("#6400ff00"));
waveColor.setDuration(7000);
waveColor.setInterpolator(new LinearInterpolator());
animators.add(waveColor);
I have no idea how to make it to just go through that colors.
Check this Link:
Hope I have understood your question properly and it helps
ColorDrawable[] color = {new ColorDrawable(Color.RED), new ColorDrawable(Color.GREEN)};
TransitionDrawable trans = new TransitionDrawable(color);
//This will work also on old devices. The latest API says you have to use setBackground instead.
mWaveView.setBackgroundDrawable(trans);
trans.startTransition(7000);
best way use ValueAnimator and ColorUtils.blendARGB
ValueAnimator valueAnimator = ValueAnimator.ofFloat(0.0f, 1.0f);
valueAnimator.setDuration(325);
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
#Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
float fractionAnim = (float) valueAnimator.getAnimatedValue();
view.setColorBackground(ColorUtils.blendARGB(Color.parseColor("#FFFFFF")
, Color.parseColor("#000000")
, fractionAnim));
}
});
valueAnimator.start();
Related
I have a view, which I want to transform into red color with an animation.
I tried to apply a color filter from 00 alpha color to FF alpha color, but when the animation starts, obviously the image it's transparent for the 00 alpha color filter, so this is not the solution:
ValueAnimator anim = new ValueAnimator();
anim.setIntValues(Color.parseColor("#00EE1B1B"), Color.parseColor("#FFEE1B1B"));
anim.setEvaluator(new ArgbEvaluator());
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
#Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
view.setColorFilter((Integer)valueAnimator.getAnimatedValue(), android.graphics.PorterDuff.Mode.MULTIPLY);
}
});
anim.setDuration(4000);
anim.start();
How can I animate a color filter from none to red?
Well finally I discovered that white color filter doesn't modify the view... so simply doing this, the problem is solved:
finalEnemyWeaponColorFilter.setIntValues(Color.parseColor("#FFFFFF"), Color.parseColor("#EE1B1B"));
I've a little difficult in using ArgbEvaluator object.
I want to change the color of view from one color to another color in specific duration.So I write this code,it works well.
ValueAnimator animator = ValueAnimator.ofArgb(Color.RED,Color.BLUE);
animator.setDuration(5000);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
#Override
public void onAnimationUpdate(ValueAnimator animation) {
int color = (int) animation.getAnimatedValue();
view.setBackgroundColor(color);
}
});
animator.start();
But I want to use ArgbEvaluator to animate like that.
public void setColor(fraction){
int color = evaluator.evaluate(fraction,startColor,endColor);
view.setBackgroundColor(color);
}
The above setColor method will be called agian and again for specific duration(eg-5000ms).
Here is my problem.
I don't know how to calculate fraction to change color within specific duration.
I want to know the calculation formula of fraction.Thanks.
How to fill a image view background such that its transparent area will be filled by some color.
I want to fill below image -
and filled image will be like -
i want to fill black area of image only with animation from bottom to top.
Please suggest some animation by which i can do desire animation.
Thanks in advance
U can try adding it in code
ImageView backgroundImg = (ImageView) findViewById(R.id.backgroundImg);
backgroundImg.setBackgroundColor(Color.rgb(100, 100, 50));
This will also solve your problem. Just add this in your ImageView tag.
android:background="#android:color/red"
Check this Im not sure. But check this snippet
You can simply use ArgbEvaluator which is available since API 11 (Honeycomb):
ValueAnimator anim = new ValueAnimator();
anim.setIntValues(color1, color2);
//anim..setIntValues(Color.parseColor("#FFFFFF"), Color.parseColor("#000000"));
anim.setEvaluator(new ArgbEvaluator());
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
#Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
backgroundImg.setBackgroundColor((Integer)valueAnimator.getAnimatedValue());
}
});
anim.setDuration(300);
anim.start();
Even better, beginning with API 21 (Lollipop 5.0) you can replace the first 3 lines in the code above with one:
ValueAnimator anim = ValueAnimator.ofArgb(color1, color2)
I'd like to animate the backgroundTint value (and ideally the alpha value too) of a FloatingActionButton, so that the FAB background color continuously switches between two colors.
My noob approach would be to use a timer that calls a function that updates this property when it fires. I'm sure there's a better way of doing this?
I got this to work using ObjectAnimator as suggested by #MH. above, but I had to override the onAnimationUpdate() callback:
final ValueAnimator animator = ValueAnimator.ofInt(Color.rgb(0, 121, 107), Color.rgb(226, 143, 34));
animator.setDuration(2000L);
animator.setEvaluator(new ArgbEvaluator());
animator.setInterpolator(new DecelerateInterpolator(2));
animator.addUpdateListener(new ObjectAnimator.AnimatorUpdateListener() {
#Override
public void onAnimationUpdate(ValueAnimator animation) {
int animatedValue = (int) animation.getAnimatedValue();
fab.setBackgroundTintList(ColorStateList.valueOf(animatedValue));
}
});
animator.start();
I am a beginner in Android development.
Coming from iOS background I tend to use animations on Views
to animate a View in Android. I have found out to do it in a "normal" way
For example to animate alpha value of a view
valueAnimator = ValueAnimator.ofFloat(0, 100);
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
#Override
public void onAnimationUpdate(ValueAnimator animation) {
float value = (Float) animation.getAnimatedValue();
viewToAnimate.alpha(value);
}
});
valueAnimator.setDuration(10000);
valueAnimator.start();
I am wondering if there is an easy way. Perhaps create a "Helper" class to animate an objects alpha value. Where we can pass in the View to animate and have it animated.
Something like AnimationHelper.animateAlpha(viewToAnimate, OF_VALUE, TO_VALUE, DURATION);
I am sorry to ask this question. Since my Java knowledge is rusty, I am wondering if there is any kind folks out there who is willing to help out.
Thank you
Try this:
viewToAnimate.animate().alpha(TO_VALUE).setDuration(DURATION);
or this:
ObjectAnimator anim = ObjectAnimator.ofFloat(viewToAnimate, "alpha", FROM_VALUE, TO_VALUE);
anim.setDuration(DURATION);
anim.start();