The following is an example of Android ApiDemos (97): Views-> Animation-> Push. ViewFlipper, ViewFlipper, and ViewSwitcher are both subclass of ViewAnimator and ViewAnimator (subclass of FrameLayout) supports the animation effects during switching between different views. ViewAnimator should be a subclass of FrameLayout. Therefore, the child views contained in ViewAnimator are stacked together, generally, you can View the top View.
ViewFlipper can contain more than two sub-views. Each sub-View is automatically displayed during regular switching. ViewSwitcher can only contain up to two subviews. Only one View is displayed at a time. It has two subclasses: TextSwitcher and ImageSwitcher. In this example, ImageSwitcher is used to switch between two contained images.
ImageSwitcher defines setImageDrawable, setImageResource, and setImageURI. You can specify an image for ImageSwitcher in different ways. Each time you call these methods, when switching between the newly added image and the previously displayed image, the animation effect specified by setInAnimation and setOutAnimation is used:
[Java]
MSwitcher = (ImageSwitcher) findViewById (R. id. switcher );
MSwitcher. setFactory (this );
MSwitcher. setInAnimation (AnimationUtils. loadAnimation (this,
Android. R. anim. fade_in ));
MSwitcher. setOutAnimation (AnimationUtils. loadAnimation (this,
Android. R. anim. fade_out ));
MSwitcher = (ImageSwitcher) findViewById (R. id. switcher );
MSwitcher. setFactory (this );
MSwitcher. setInAnimation (AnimationUtils. loadAnimation (this,
Android. R. anim. fade_in ));
MSwitcher. setOutAnimation (AnimationUtils. loadAnimation (this,
Android. R. anim. fade_out ));
In this example, ImageSwitcher is displayed on the top of Layout, and the thumbnail of the image is displayed using Gallery. For details about Gallery usage, see Android ApiDemos example resolution (119): Views-> Gallery-> 1. Photos
When you select a thumbnail in the Gallery, ImageSwitcher is used to display the corresponding large image:
[Java]
Public void onItemSelected (AdapterView parent,
View v, int position, long id ){
MSwitcher. setImageResource (mImageIds [position]);
}
Public void onItemSelected (AdapterView parent,
View v, int position, long id ){
MSwitcher. setImageResource (mImageIds [position]);
}
Author: mapdigit