10

I have an ImageView element that I create in my code and place inside of my RelativeLayout. I set this image to be Invisible to start off with using the following code:

arrow.setVisibility(View.INVISIBLE);

I then defined a Fade-In Alpha animation via XML:

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false"
android:fillEnabled="true"
android:fillAfter="true"
android:fillBefore="true">

<alpha
    android:fromAlpha="0.0"
    android:toAlpha="1.0"
    android:startOffset="100"
    android:duration="300" />

/set>

To run the animation:

I simply call the following to start the animation

myview.startAnimation(myanimation);

The issue I am seeing is that my animation causes the ImageView to flicker in at full visibility and then go through the animation of alpha 0 to 1. How do I fix this? I can't set the initial alpha value to 0 because the alpha animation is based on percentage and not absolute alpha value. (ex: 0*current value to 1*current value)

Any help would be greatly appreciated.

Derek Gebhard
  • 917
  • 2
  • 10
  • 15
  • Well it looks like the issue is due to running the animation on the completion of another animation for a different view object. Can anyone recommend a fix? – Derek Gebhard Feb 01 '13 at 17:55
  • Android will take care of canceling another animation on the same view. You say that it is a *different* view that has the interfering animation. Perhaps you can cancel it through `clearAnimation()`? – Paul Lammertsma Feb 01 '13 at 23:28
  • I am starting to think this issue is just an Android bug. I have seen it mentioned elsewhere without an answer and the animation I am doing doesn't really interfere. Its just that I am starting this fade in animation when the other one ends. I tried clearAnimation with no luck. I still get the flicker – Derek Gebhard Feb 04 '13 at 05:51
  • Can you post some more code. What is arrow and what is my view ? – Anirudha Agashe Mar 01 '14 at 18:40

2 Answers2

2

I think the problem is, with this line of code:

android:fillBefore="true"

Here, Try this code instead, it works for me :

<?xml version="1.0" encoding="UTF-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="2000"
    android:fillAfter="true"
    android:fromAlpha="0.0"
    android:toAlpha="1.0" />
Amin Keshavarzian
  • 3,646
  • 1
  • 37
  • 38
  • I was having the same issue. In my case `introAnimation.setFillBefore(true);` solved the issue – Buddy Sep 16 '15 at 18:48
0

If you are using animateLayoutChanges in your layout file in combination with the animation, toggling the View visibility will result in two animations running and the view flashing or blinking. Setting view visibility causes the layouts animateLayoutChanges to run and to fade the view in once and then the animation you created causes a second animation to run as well.

CodeSmith
  • 1,621
  • 1
  • 13
  • 31