Monday, June 24, 2013

Android ImageSwitcher Example

ImageSwitcher

A ImageSwitcheris a specialized ViewSwitcher that contains only children of type ImageView. A ImageSwitcher is useful to animate an Image on screen.ImageSwitcher
switches smoothly between two images and thus provides a way of
transitioning from one Image to another through appropriate animations.

In the below snapshot we can see an Image is coming IN and other Image is going OUT

Two types animations are required for for ImageSwitcher to switch between the texts.1: In Animation: with which Image come in the Screen.2: Out Animation: with which Image goes out from the Screen.

We can provide following Animations

For In Animation R.anim.slide_in_left R.anim.fade_in

For Out Animation R.anim.slide_out_right R.anim.fade_out

In Example, I have an ImageSwitcher and a button called "NEXT" , when user clicks on NEXT
button ImageSwitcher will switch between Images . The current Image will
go OUT and next Image will come in with specified Animation.

ImageSwitcher Example:

In this Example I have following layout

In the above layout, we have an ImageSwitcher and a button called "NEXT" , when user clicks on NEXT
button ImageSwitcher will switch between Images . The current Image will
go OUT and next Image will come in with specified Animation.

// Declare the animations and initialize them Animation in = AnimationUtils.loadAnimation(this,android.R.anim.slide_in_left); Animation out = AnimationUtils.loadAnimation(this,android.R.anim.slide_out_right);

// set the animation type to imageSwitcher imageSwitcher.setInAnimation(in); imageSwitcher.setOutAnimation(out);

// ClickListener for NEXT button // When clicked on Button ImageSwitcher will switch between Images // The current Image will go OUT and next Image will come in with specified animation btnNext.setOnClickListener(new View.OnClickListener() {

12 comments:

Hi AjayThe example is complete, slide_in_left and slide_in_right are not used here, but if you still want those files, kindly go to http://learnandroideasily.blogspot.in/2013/06/android-viewflipper-example.html