Android ViewFlipper - Androhub

ViewFlipper

Android ViewFlipper

ViewFlipper is an extension class of ViewAnimator, which animates between two or more views that have been added to it. Specfically, only one child is shown at a time.

To learn Basic of Android Animation  go to  Android Animation Tutorial.

To get a better understanding, suppose that we have two TextViews that will be used in our app, but we want only one to be displayed at a time. That is, here is the most popular use case that ViewFlipper fits in.

Example

In this example i will demonstrate you how to work on viewflipper with animations.

VIDEO DEMO

Let’s get start by creating a project in Eclipse IDE.

1. Create a new project in Eclipse by navigating to File ⇒ New Android ⇒ Application Project and fill required details. (I kept my main activity name as MainActivity.java)

2.  Create a layout file for MainActivtiy.java under res ⇒ layout folder. I named the layout file as activity_main.xml. In this layout i had taken one viewfilpper for flipping the views and inside the viewflipper i had taken four different views.

3. Now, create a new folder in res folder naming anim for animation files. In this folder create two xml files naming left_out.xml and right_enter.xml.

4. Now, add the following code to your MainActivity.java. In this file i am going to show using of viewflipper.

5. Now, run the app and you will get the output as shown in video.

Thanks. :)

 

Post comment

Your email address will not be published. Required fields are marked *