As I believe in the power of XML (for layouts), this is the equivalent for the accepted answer, but purely as an animation resource:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:interpolator/accelerate_decelerate"
android:fillAfter="true">
<alpha
android:fromAlpha="0"
android:toAlpha="1"
android:duration="1000" />
<alpha
android:fromAlpha="1"
android:toAlpha="0"
android:duration="1000"
android:startOffset="1000"/>
</set>
The fillAfter
is for the fade to remain after completing the animation. The interpolator
handles interpolation of the animations, as you can guess. You can also use other types of interpolators, like Linear or Overshoot.
Be sure to start your animation on your view:
yourView.startAnimation(AnimationUtils.loadAnimation(co??ntext, R.anim.fade));