Android view fade in programmatically - android

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)

Related

Android animate view along a curved path

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.

TextViews animate only once on Android 4

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.

Alternative to Translate Animation

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.

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

Android: Move View after animation?

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.

Categories

Resources