I'm trying to move my image from one point to another using this answer to achieve my animation. However this animation is not showing. Below is the code I'm using
ArcTranslate animation = new ArcTranslate(1000,Animation.ABSOLUTE,fromPos[0],toPos[0],Animation.ABSOLUTE,fromPos[1],toPos[1]);
animation.start();
I'm having another doubt too. How does this animation figures out which view to animate? Does it just takes the view in the given fromPos??
You should attach the animation to a view. Usually, the following works well:
View.startAnimation(animation);
If you use this, remove the animation.start(). Alternatively you can first attach the animation, and start it later:
View.setAnimation(animation);
And then call animation.start() later.
Related
I tried searching around and found that you have to set a listener to change the actual position of the view when the animation ends. But the thing is, I don't know how I can get the end values from the ObjectAnimator I am using.
Isn't there an easy way to do this aside from setting listeners to all of my Animators, there are like 9 of them. Something like a setFillAfter(true) I always see that but I can't seem to find what Animator object uses it.
It turns out you have to have an AnimatorListener attached to the Animators that will do this for you. But that is too much for me because I have multiple Animators. So what I did, I positioned them on the layout in what they would be after the end animation, then I made the Animator to animate from the start position to their end position. That way I don't have to fret over the actual positions of the views
I am using animators (ObjectAnimator) to animate few properties (scale, rotate) of a view.
Target view is animating properly when ObjectAnimators are set to it.
But there is an added requirement to get view to the original position (reset) after a while.
I tried to cancel() the animator but it only cancels the animation and doesn't reset the view.
Possible solution : creating another animator that does just opposite of the initial animator.
Is there any other way to reset it ?
See the solution I came up with as I had a similar issue with animations inside views in a recycler view, so I had to find a way to reset them:
Trying to reset values from Property Animator to be used in recycler view
Good news in Android O these will be better supported
I met the same problem, because I animate the view use ViewPropertyAnimator, addView() and removeView() again and again for not creating new view, but a view can be shown once, when you remove the view, you call addview() again, it is no show, but you see the property visibility is visible and animationListener also be called. it is strange.
I had the Same problem with my views . so I came over this problem with this trick .
So We assume we have a view that applying an animate after clicking on it .
viewLayout.arrow_back.setOnClickListener {arrow ->
arrow.animate().rotationXBy(50F) // this is a just simple anim not so usefull
.start()
arrow.isEnabled = false
}
I hope it'll Help someone .
Both ObjectAnimator.cancel() and ObjectAnimator.end() don't cancel the effects the animation had on the animated object, but rather just cancel its execution at the point in which the methods were called (see ValueAnimator's documentation for more details).
Now, I can think of three main ways to accomplish what you wanted:
Put a listener on the ObjectAnimator, and when OnAnimationEnd/OnAnimationCancel is called, manully reset the properties of the view.
If the properties of the view you want to reset are those given to it in the XML file, you can re-inflate it. For more details, check out this answer.
Use the ObjectAnimator.reverse() method to reverse the execution of the animation, effectively reseting the properties of the view. Preferably, you would want to call start the reverse when the animation ends, so you'd probably need to put a listener on the animator and check when OnAnimationEnd with the animtor to reverse is called.
Do you mean stop a running animation? If so, call clearAnimation() to remove animations from the views that you called startAnimation();
If what you mean is to reset the view to its original appearance after the animation is over, always setFillAfter(false); to the animations.
I finally came to know that when using translate animation, the button onclick listener won't work.
This is the link to the full description of my problem
Now I would like to know what is the alternative options to try instead of Translate Animation.
You can use your own animation using a thread.
I can give you an example.
Put your view to animate inside a Relative Layout.
Then start a thread which is running a loop with specific delay time and then set the margin of the view that you need to animate with different values..
This will give you the effect of translate animation and the view will be intractable also.
I'm adding an ImageView dynamically to my layout and then I want it to fade in. Unfortunately the image is added and then the animation is applied, so it has a flicker to it BEFORE the animation starts. I've tried to initially set the alpha to 0 then AlphaAnimate that in, but it never shows up. I tried using Invisible or Gone on the view visibility.
I'm using an AnimationSet to fade in with other animations, then wrapping that in another AnimationSet. Could this be the issue?
Code for animation is pretty simple. no tricks. but the view looks like it's added then taken away using this.
AlphaAnimation fadeIn = new AlphaAnimation(0,1);
fadeIn.setDuration(duration/3);
fadeIn.setFillAfter(true);
Removing it from a nested AnimationSet solved the issue. I was doing an alpha/tranlate/scale in an AnimationSet, then doing 2 of those in another AnimationSet to do a zoom in/zoom out scenario
Are you using AlphaAnimation.setFillAfter(true)?
http://developer.android.com/reference/android/view/animation/Animation.html#setFillAfter(boolean)
I'm trying to basically have a button move down to the bottom of the screen with an animation after it is clicked.
I have the animation working perfectly, but the button doesn't stay at the bottom of the screen after the animation finishes. I've tried using offsetTopAndBottom(), but it only stays down there for one frame, and is redrawn at the top. How can I get the button to stay?
Did you try to call setFillAfter(true) on your animation instance?
Regards!
Yes, setFillAfter(true) works.
But the strange thing is that corresponding android:fillAfter XML attribute does not provide same effect. Be aware, guys.
Your button is not clickable because you are using View animation instead of the Property Animation.
View animation only change where your View is drawn instead of really moving it to that location.
Property animation does the trick.
I answered your question on another thread.
You can check it out here.