Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Alpha Fade in Animation Issue

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.

like image 318
Derek Gebhard Avatar asked Feb 01 '13 17:02

Derek Gebhard


People also ask

What is Alpha in android animation?

An Alpha Animation is animation that controls the alpha level of an object, i.e. fading it in and out.

How do I turn off infinite animation on Android?

Use clearAnimation() to stop an animation.


1 Answers

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" />
like image 90
Amin Keshavarzian Avatar answered Oct 26 '22 01:10

Amin Keshavarzian