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.
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'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.
I am making a game in which I have 5 buttons, looking like clouds, falling from the "sky".
That means that when my activity starts, 'clouds' cannot be seen, since the marginTop is set to -100dp.
From that position they start falling down untill they get lost on the bottom side of the screen.
The thing is, I need those buttons to be clickable, during the process of animation.
So far, I found some documentation about how I can make the buttons clickable AFTER the animation ends. But I don't need that. I need to be able to click on the buttons through the animation time itself.
NOTE: I need something that works with versions before 3.0.
Anybody has any link to documentation or some example or anything ?
After doing some research, I found out that there are two types of animations:
View Animation and Property Animation.
The view animation can only animate View objects. It also lack a variety of animations, since it can do only stuff as scale, rotate, move... It cannot change background color, for example.
Also, the disadvantage of the View Animation is that it only change the position of where the View object is DRAWN. Physically, it still stays in the same position.
That's why the button is un-clickable, after the View Animation is finished upon it.
Property Animation, in the other hand, can animate both View and non-View objects and it doesn't have constraints as the View Animation.
When objects are moved, for example, with the property animation, they are not just drawn on some other position on the screen, but they are actually MOVED there.
Now, Property Animation is a lot more complex to write than the View Animation, so if you don't really need all the advantages of the Property Animation, it is suggested to use View Animation.
Source:
Property vs View Animation
Tutorial and SupportLybrary up to API 1:
nineoldandroids
You can change the buttons to imageViews and then do
imageView.setOnClickListener(myListener)
then set myListener to do whatever you previously wanted to happen on the buttons onClick. Your activity will have to implement OnClickListener
Added bonus: you can make the images look like clouds :)
I have a text view where in i have to keep ages between 1-99. I also have two buttons ^ and v(i mean up and down arrows) on clicking them the values of the age should smoothly scroll to next or previous value.
I have been trying different ways but couldnt achieve smooth scrolling. Can anyone please give me any idea of how to achieve the task.
I think the easiest way is to simply put the TextView within a ScrollView, and let the arrows interact with the ScrollView, by using things like the fling method and playing around with the velocity parameter to suit your needs.
Use the animation framework.
When pressing down, start the 'down'-animation.
When pressing up, start the 'up'-animation.
Read more about animation here: http://developerlife.com/tutorials/?p=343
View animation is not much matured and hence i am noy sure if that can be used for moving the views.
Please find the description below:
Another disadvantage of the view
animation system is that it only
modified where the View was drawn, and
not the actual View itself. For
instance, if you animated a button to
move across the screen, the button
draws correctly, but the actual
location where you can click the
button does not change, so you have to
implement your own logic to handle
this.
Source
To scroll smoothly you can try using the scroller component.
Reference
What you would need to do is pass the duration of the scroll in the constructor and then use the property
setFinalY(int newY)
to increment the counter position by 1 unit (equal to the height of the item).
Please let me know if that helps!
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.