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 :)
Related
I draw a View that is not attached to any parent.
It's a decoration for a RecyclerView. The view sticks to the bottom and disappears when its counter part comes up in the list.
All this works fine but:
When i leave the activity the View doesn't fade with the rest of the
views in the activity's transition.
It stays until the end of the animation and then disappears
immediately.
( see large green view in the demo )
How do i include this unattached View in the activity's exit transition?
I've create a minimal Android Studio Project to replicate the issue:
https://github.com/Ostkontentitan/transition-issue-demo
(To better see the issue possibly set your phones animation scale to >= 5)
Here is a demo:
Add transitionName to xml layout for the RecyclerView.
The transition animation you see is because of ActivityOptions.makeSceneTransitionAnimation(this#ItemListActivity) and if you add transitionName to the view, it works fine.
Not-too-educated guess
(because I haven't tried and I haven't used Transition Framework in a few months)
The way TF (Transition Framework) works is by computing the start/end values of the transition and performing the animations needed to achieve this.
RecyclerView decorations are not "views" that are part of the layout, so TF has no idea that thing exists. It does know about your RecyclerView of course, because it's contained in the ViewGroup that is animated.
You may have already know this, but in any case, what I think I'd try to do here, is create a custom transition framework transition (they are not hard to do, you can even check TransitionEverywhere and look at how that library implements some missing transitions in the framework); in your CustomTransition, you can then try to interpolate the animation values so the recycler view can redecorate as the animation progresses (like an alpha value that is animated, your custom decorator would "paint" using said alpha).
Now... in truth, I've had to do something similar once, where a custom transition was "driving" a few external views (for reasons at the time) :) but... it was not a RecyclerView item decoration, mine were just "views", so I'm not sure if you can do this this way w/a decoration.
I think it's worth trying.
I have a card-like view with elevation and a white background that I want to expand to fill up the whole screen. It's a card in a list (my own custom layout, not a CardView), and I want to make it take up the whole screen when it's tapped via a Fragment transition.
My first idea is to create a fake, identical view in the new fragment, place it at the item's position, and animate it to the top, while animating its layout bounds to take up the whole screen. However, I don't think this is the best idea, as Android will have to remeasure the layout every single frame while the animation is running (likely to lag). Is there a way I can get this effect in a clean way? I'm going to be using fragment transitions, so hopefully I can use Animator in some way, but I'll take any solution.
You can try to do the same, but instead of relayouting, do redrawing. Create custom implementation of view's onDraw(), it's not that hard.
View will fill entire screen but at the start of animation will draw only initial part.
Or you can just try your approach, it's easy to implement and may be it is not that slow.
Also, may be directly modifying view's setLeft(), setRight(), etc. with Animators is a valid solution.
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've got an absolute layout. In that layout is a custom view that takes up the left 3rd of the screen. I put a button in the layout that I want to cause the custom view to slide on and off of the screen. I've tried using animation resources (translates... "slidein" and "slideout") and the function startAnimation on the custom view, but I can't get the behavior I am looking for.
OK... I start with the custom view visible and in onCreate I find the view and animate it off screen using my slideout animation. That works fine. I figured out that I need to set "fillAfter" in the animation so that the custom view stays off screen.
Now, when I press my button I want to cause the custom view to slide back on the screen, so I trigger my slidein animation using startAnimation again but with slidein. BUT... that causes the view to first jump back to its original position AND THEN slide to the right... causing it to finish in the middle of the screen.
How do I get the animation to use the view's current position as the animation starting position, not its original position?
Thanks
I also experienced the flicker described in this question. My solution was to use the improved Honeycomb animation APIs. There is a convenient library that ports these all the way back to Android 1.0:
http://nineoldandroids.com/
For more on Honeycomb Animation APIs see:
http://android-developers.blogspot.com/2011/02/animation-in-honeycomb.html
In my case I had 2 overlapped LinearLayouts inside a RelativeLayout. I wanted to slide the top LinearLayout off the screen and reveal the bottom LinearLayout below. Then I wanted to slide to top LinearLayout back on screen to its original position so the top layout covered the bottom layout again. Using the old animation APIs I was seeing a flicker before the second animation (offscreen -> onscreen) was starting.
With the new APIs this task turned out to be trivial:
// Slide out (add to button handler)
ObjectAnimator.ofFloat(mTopLayout, "translationY", mTopLayout.getHeight()).start();
// Slide back in (add to button handler)
ObjectAnimator.ofFloat(mTopLayout, "translationY", 0).start();
The Honeycomb Animation APIs actually move objects around on the screen (rather than pretending to move them like the older animation APIs), so there is no need to fool around with filleAfter, fillBefore, etc.
Look into setting the fillAfter property to keep the end animation state
I am trying to swap two LinearLayouts by setting their visibility properties to "VISIBLE" and "GONE" respectively. I am also using an animation while the layouts are being swapped. The animation completes successfully and I see the correct layout. However, the previous Layout which has its visibility property set to "GONE" still receives clicks even though it's not visible. At the same time, the layout which is "VISIBLE" receives clicks only when clicked in area where the "GONE" layout isn't clickable. I am also calling the requestFocus method on the "VISIBLE" layout. But it doesn't help.
Moreover, if I skip the animation part and just set the visibility properties, everything works correctly.
What am I missing here?
If you are animating widgets, you need to make changes to the layout to have the results "stick". Just using the fillAfter stuff will give you some of the effects you see -- it is drawing them in the new location but they aren't really in the new location.
So, I would start by turning off any fill* settings (e.g., fillAfter) in your animation. See what your animation behaves like then. Most likely, it visually will now depict what the clicks tell you.
Then, set up an AnimationListener to get control when the animation ends, and at that point, make real changes to the widgets and their containers to affect your end positions.
Here is a sample project that demonstrates what I mean, albeit in an overly complicated fashion, since I am animating a custom View rather than an off-the-shelf widget.