TextViews animate only once on Android 4 - android

I have a layout (RelativeLayout) with a number of buttons and two text views. For each change of information I fade out all the views, update the information and then fade in the views. I use layoutanimations for this.
The very strange thing is that the text views can only be animated once. They fade in and out correctly one time and then won't get animated anymore. The buttons, on the other hand, continue to animate just fine.
Another perhaps strange thing is that I don't get this problem on android 2.3.x but on android 4.0.x.
I can work around the problem by clearing animations on the text views after fade in, but it doesn't look so nice since they still don't get faded in.
I have tried to clear animations on the text views before fade in but it doesn't help. I have also tried different settings of the targetSdkVersion property in the manifest, but without any results.
The fade in animation (fade out is similar):
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="750"
android:fillAfter="true"
android:fromAlpha="0.0"
android:interpolator="#android:anim/accelerate_interpolator"
android:toAlpha="1.0"
/>
The animation code (this is run everytime the layout is to fade in):
// Set listener.
viewGroup.setLayoutAnimationListener(listener);
// Load animation.
final Animation fadeIn = AnimationUtils.loadAnimation(context, R.anim.fade_in);
// Create and start animation controller.
final LayoutAnimationController animController = new LayoutAnimationController(fadeIn);
viewGroup.setLayoutAnimation(animController);
animController.setAnimation(fadeIn);
animController.setDelay(FADE_IN_DELAY + extraDelay);
animController.setOrder(LayoutAnimationController.ORDER_REVERSE);
animController.start();
Does anyone have any idea? Is there some kind of animation specific difference between Buttons and TextViews? Are there any animation changes in Android 4 that breaks the backward compatibility?
Thank you!

Layout animations occur only when a view group lays out it's children - as per the [LayoutAnimationController][1] docs the same animation is played for each child, but with a different starting time - it's generally used for e.g. a ListView or GridView to animate the entrance of the items.
The animation will not generally be played when you update your content. You'll need to use View.startAnimation(Animation) and View.clearAnimation() to ensure your animations are played each time you update your content.

Related

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

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.

UI animation in android

I have view with several components on it. I use Linear layout with vertical orientation
When user unchecks some checkbox I need to hide one EditText and other components moves up
edtPhone.setEnabled(false);
works well, but everything happens immediately and i want to do it slowly and animated
How can i do it in android?
Create a TranslateAnimation, assign an AnimationListener to it and in onAnimationEnd() you should set the visibility of your EditText to View.GONE (or View.INVISIBLE, it depends on your needs) and do whatever you want when the animation has stopped.
Remember to assign the TranslateAnimation to the other components that should move up. In order to get your TranslateAnimation to move slowly, use android:duration in XML or Animation.setDuration() in code, with a defined value in milliseconds (maybe 500 milliseconds?).

Android view fade in programmatically

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)

Struggling with view animations

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

Categories

Resources