Struggling with view animations - android

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

Related

Scene Transition Flicker

I have a simple view containing a scene root FrameLayout, ListView and a couple of buttons on the bottom.
scene root is used to load and show different scenes, the size changes dynamically depending on the current scene. ListView is set to match_parent in both directions and is positioned behind scene root.
Here's the issue:
If I start a transition using the buttons on the bottom everything works ok, no problem, magic. However, if I transition (✝) to a different scene while scrolling (✝✝) the transition seems to flicker before starting.
It almost looks like the rendering engine fails to load the first frame of the animation before the ListView invalidates the hierarchy due to scrolling.
Thanks for the help ;)
✝ TransitionManager.go(Scene, Transition)
✝✝ I've added a couple of methods to the ListView to allow that
All the Google apps that use Scene Transition that I've seen transit from some item in a ListView to its detail Activity. Since ListView has the convenient behavior of immediately stop the scrolling when touched, such a transition doesn't produce flickering.
So it appears the best thing to do may be to programmatically stop the scrolling before transiting to the new Activity, which is accomplished by the code here.

Android Animation - Button stays clickable

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 :)

New position of layout during animation is resetting after ui interaction

I am working in android 2.3 and I have an issue which is a bit of a pain.
I have 2 layouts on top of each other in a FrameLayout. The top layout is moved partly off-screen during an animation, and the .layout() method is called in the animation end. This works great and the ui is moved correctly and the buttons of the toplayout is still clickable.
After the animation the second layout is visible as the toplayout is moved off-screen. This layout contains a list which is clickable and each cell has an ImageView which is updated when clicked. However my problem is, when the table cell is clicked and the ImageView is updated, the entire view is reset, ignorering the animation and new location of the toplayout. It just sets the toplayout back on top as the animation never happend.
I use an TranslateAnimation and the set fillafter is set to true as well.
Do you guys have any suggestions to what I might be missing.
I guess your problem is placing objects inside FrameLayout. As described in this answer you cannot place a view inside a FrameLayout by setting its location.
It's true that with FrameLayout all children are pegged to the top
left of the screen, but you still have some control with setting their
padding. If you set different padding values to different children,
they will show up at different places in the FrameLayout.
Use padding instead to "move" the view off-screen.

Slide navigation menu from bottom

I'm trying to implement a sliding menu, like in Prixing app. (The menu which lays under main layout and get visible when you take and drag main layout to the side)
But the trick is - i want it to appear on bottom of the screen, so I need to move the main layout to the top.
The second problem is that in tah layout I got a listview.
Please, I really need advices or maybe link to some usefull resources where I can understand how touch events are handled.
Thx!
i think you are try to do same as facebook app. i have found demo for it. so use this
there's really no magic on it.
To make it, move directly (in a button click or something):
you use a animation to change the LayoutParams.top from both fragments (the one on top (currently in view, and the one on the bottom, hidden under the screen).
On your XML layout make sure to set a fixed height for the bottom layout (in DIP) and during runtime animate the two layouts to move that amount of pixels.
To make it move with the user finger:
That will be tricky, because the listview MUST receive the the user input. Maybe if you call super on it.
But you can accomplish it by receiving OnTouchEvents:
TOUCH_DOWN, you start the move (mark it with a boolean or something)
TOUCH_MOVE, you apply the same change to the layout params that you did on the animation (1st option)
TOUCH_UP or TOUCH_CANCEL, you stop the move (clear the flag).
hope it helps pointing you to the right direction.

Android - Animation on widgets

I started with a simple animation on button,
I am successful to an extent,
The problem i am facing is, I am able to animate the button but the position of listener,
Even after button is animated the clickable area is not animated , It is resting at the original postion
Could some one help me with an useful code snippet or suggestion
Regards
Android animations can not change the layout of buttons or view in general. Only their image will appear to move, but they will stay in the same place. After the animation is finished, get the Layout parameters through View.getLayoutParams() and change them.

Categories

Resources