I have the following animation
ValueAnimator colorAnim = ObjectAnimator.ofInt(contentBg, "backgroundColor", /*transparent*/0x0, /*dark*/0xcc000000);
colorAnim.setDuration(3000);
colorAnim.setEvaluator(new ArgbEvaluator());
colorAnim.start();
so what I want is to animate a contentBg from transparent to almost opaque dark. However, what I gets is just a transparent view, and after 3 seconds it gets instantly dark (end value of animation).
What should I do to make it work properly?
I am using nineoldandroids lib.
Have you tried to animate alpha only?
ValueAnimator colorAnim = ObjectAnimator.ofFloat(contentBg, View.ALPHA, 0, 0.8);
colorAnim.setDuration(3000);
colorAnim.start();
EDIT: from here it seems there is a problem with ArgbEvaluator evaluating alpha values. You can try the patched version provided in https://github.com/EaseTheWorld/PaintAnimator/blob/master/src/dev/easetheworld/animator/ArgbEvaluator2.java
Actually solved it myself by narrowing down my question to animating just alpha.
How to set View alpha in lower Api than 11?
Related
I'm trying to use a very simple code to fade the background color change in a textview
the idea is to chose a new color, than have it fade from transparent to the desired color, here is the code:
ValueAnimator anim = new ValueAnimator();
anim.setEvaluator(ArgbEvaluator.getInstance());
anim.setDuration(1500);
anim.setIntValues(hightlightColor & 0x00FFFFFF, hightlightColor);
// txtView.setBackgroundColor(hightlightColor);
anim.addUpdateListener(animation -> txtView.setBackgroundColor((int) animation.getAnimatedValue()));
anim.start();
highlight color is just a green i'm using for example, txtview is a valid textview and the current background is null
but instead of creating a fade in shades of green the code results in a crazy rainbow like interpolation, that ends exactly in the desired green, but all intermediate values are shit
I thought it might be the alpha channel so i tested starting from white to green but the intermediate colors were all crazy also
MY APP MINSDK IS 16 SO I CANT USE ValueAnimator.ofArgb()
here is how it looks
Like the title said, I'm looking a easy way to customize the color used in reveal.
I want to use official code if it's possible (avoiding 3rd party libraries).
I'm using the usual code:
Animator anim = ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0, finalRadius);
myView.setVisibility(View.VISIBLE);
anim.start();
The circular reveal animation doesn't have any color. If you want color, you need to set the background color on the view you are providing to circular reveal.
I want to rotate a simple imageview which has an elevation of 5dp.
animRotate=ObjectAnimator.ofFloat(imgProgress, "rotationY", 0, 360);
animRotate.setDuration(ANIM_DURATION);
animRotate.setRepeatCount(5);
animRotate.start();
The animation for the above code is smooth if the android:elevation value for the ImageView is not set in the layout file. But when i set the elevation, the animation becomes jerky.
Can someone please suggest a fix?
Maybe the reason is that you create and run animatuion at once. As docs say, it is better first to init your animation
//OnCreate
animRotate=ObjectAnimator.ofFloat(imgProgress, "rotationY", 0, 360);
animRotate.setDuration(ANIM_DURATION);
animRotate.setRepeatCount(5);
And then when it is time for animation to be fired run it
animRotate.start();
Also, consider reading about what PivotX and PivotY are, it may be useful.
Also, using default interpolator will give strange result for rotating 5 times - i think using simple linear interpolator is much better choice.
I have a view that is positioned totally off screen and I am trying to animate it onto the screen.
When I call:
view.startAnimation(tA);
nothing happens, tA.initialize and tA.applyTransformation never get called.
If I move the view so that any part of it is visible before I start the animation, then the animation works correctly.
What is preventing a view from being animated when it is positioned off the parent View?
It's my understanding from researching the same problem that Android Animations do not do well when provided with offscreen coordinates for their start or finish.
There is some dialog on the Android forums about this bug having been addressed but I'm still experiencing problems on 4.2.
Edit:
On second thought, I just ran across this answer and it provides a working alternative if you can use the newer APIs (ObjectAnimator).
View view = this;
ObjectAnimator anim = ObjectAnimator.ofFloat(view, "y", 0, 100);
anim.setDuration(super.animationDuration());
anim.start();
Where the properties of ObjectAnimator.ofFloat(view, "y", 0, 100); are
ObjectAnimator.ofFloat(Object objBeingAnimated, String propertyBeingAnimated, float startValue, float endValue)
I found this answer using ValueAnimator to modify the MarginLayoutParams.topMargin (in my case) in onAnimationUpdate(), which fixed the issue. My View starts out with its margin set so that the View is off screen.
The ObjectAnimator approach was promising but did not work for me, it had the same cutoff issue for off-screen views that I got with TranslateAnimation.
I need to set the initial transparency for a TextView, but I don't know how to do it. On iPhone/iOS, it can be done easily with the alpha property. On Android, I've tried to set the alpha using AlphaAnimation but it's no good -- it doesn't work. It just returns to 100% alpha when the animation ends.
AlphaAnimation anim = new AlphaAnimation(1, 0.2f);
anim.setDuration(5000);
textView.startAnimation(anim);
Any ideas guys?
You can set the alpha channel directly in a color value that you assign to the TextView. See Available Resource Types.