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!
To use Fade In or Fade Out animations in our android applications, we need to define a new XML file with <alpha> tag like as shown below. For Fade In animation, we need to increase the alpha value from 0 to 1 like as shown below. <? xml version="1.0" encoding="utf-8"?>
An Alpha Animation is animation that controls the alpha level of an object, i.e. fading it in and out.
A property animation changes a property's (a field in an object) value over a specified length of time. To animate something, you specify the object property that you want to animate, such as an object's position on the screen, how long you want to animate it for, and what values you want to animate between.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With