7

I would be very grateful if someone could explain to me why this works:

private void startAnimating() {
    TextView logo1 = (TextView) findViewById(R.id.Shizzle);   
        final Animation fade1 = new AlphaAnimation(0.0f, 1.0f);  
        fade1.setDuration(3000);
        logo1.startAnimation(fade1);
        }

But this doesn't work at all for me:

private void startAnimating() {
    TextView logo1 = (TextView) findViewById(R.id.Shizzle);   
        Animation fade1 = AnimationUtils.loadAnimation(this,R.anim.fade_in);  
    logo1.startAnimation(fade1);    
    }

The fade_in.xml associated with the above is:

    <?xml version="1.0" encoding="utf-8"?>
<set
    xmlns:android="http://schemas.android.com/apk/android"
    android:shareInterpolator="false">
    <alpha
        android:fromAlpha="0.0"
        android:toAlpha="1.0"
        android:duration="3000">
    </alpha>

Thanks for your help!

1 Answer 1

13

Works for me: Create two file in folder /res/anim - fadein.xml, fadeout.xml

fadein:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >

    <alpha
        android:duration="500"
        android:fromAlpha="0.0"
        android:toAlpha="1.0" >
    </alpha>

</set>

fadeout:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >

    <alpha
        android:duration="200"
        android:fromAlpha="1.0"
        android:toAlpha="0.0" >
    </alpha>

</set>

initialize code:

Animation animFadeIn, animFadeOut;
...
animFadeIn=AnimationUtils.loadAnimation(this, R.anim.fadein);
animFadeOut=AnimationUtils.loadAnimation(this, R.anim.fadeout);

... using:

case R.id.imgBtnShowContent:
    rlOrderBtns.startAnimation(animFadeIn);
    rlOrderBtns.setVisibility(View.VISIBLE);
break;

case R.id.imgBtnHideContent:
    rlOrderBtns.startAnimation(animFadeOut);
    rlOrderBtns.setVisibility(View.INVISIBLE);
break;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.