Android Programming Tutorials

(Romina) #1
Now Your Friends Seem Animated

private void toggleStatusEntry() {
if (statusRow.getVisibility()==View.VISIBLE) {
statusRow.startAnimation(fadeOut);
}
else {
statusRow.setVisibility(View.VISIBLE);
statusRow.startAnimation(fadeIn);
}
}

You will also need to add imports for android.view.animation.Animation and


android.view.animation.AnimationUtils.


At this point, you can rebuild and reinstall Patchy, and you will see your


status entry area fade out when you hide it, then fade back in when you


show it again.


Extra Credit...............................................................................................


Here are some things you can try beyond those step-by-step instructions:



  • Have the status entry widget slide out rather than fade out, either
    sliding out to the top or sliding out to one side.

  • Use an AnimationSet to have the widget both fade and slide.


Further Reading........................................................................................


So-called "tweened" animations, such as the AlphaAnimation used in this


chapter, are covered in the "Animating Widgets" chapter of The Busy


Coder's Guide to Advanced Android Development. This includes coverage


of other types of tweened animations (slides, spins, etc.), how to apply


several animations in parallel or sequence, etc.


270
Free download pdf