{"id":12542,"date":"2014-08-05T11:00:53","date_gmt":"2014-08-05T08:00:53","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=12542"},"modified":"2019-04-24T16:04:49","modified_gmt":"2019-04-24T13:04:49","slug":"android-viewflipper-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/viewflipper\/android-viewflipper-example\/","title":{"rendered":"Android ViewFlipper Example"},"content":{"rendered":"<p><code>ViewFlipper<\/code> is an extension class of <code>ViewAnimator<\/code>, which animates between two or more views that have been added to it.  Specfically, only one child is shown at a time.<\/p>\n<p>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 <a href=\"http:\/\/developer.android.com\/reference\/android\/widget\/ViewFlipper.html\" target=\"_blank\" rel=\"noopener noreferrer\"><code>ViewFlipper<\/code><\/a> fits in.<\/p>\n<p>What we are going to implement in this example, is rendering two simple screens using ViewFlipper. We &#8216;ll also try to create a basic animation while navigating between them. Let&#8217;s go!<\/p>\n<p>For the need of this example, we will use the following tools in a Windows 64-bit platform:<br \/>\n&nbsp;<\/p>\n<ol>\n<li>JDK 1.7<\/li>\n<li>Eclipse 4.4 Luna<\/li>\n<li>Android SDK 4.4<\/li>\n<\/ol>\n<div class=\"tip\"><strong>Tip<\/strong><br \/>\nYou may skip project creation and jump directly to the <a href=\"#code\"><strong>beginning of the example<\/strong><\/a> below.<\/div>\n<\/p>\n<h2>1. Creating a New Android Application Project<\/h2>\n<p>Open Eclipse IDE and go to File \u2192 New \u2192 Project \u2192 Android Application Project.<\/p>\n<p>Fill in the name of the application, the project and the package in the appropriate fields and then click Next.<\/p>\n<p><figure id=\"attachment_12549\" aria-describedby=\"caption-attachment-12549\" style=\"width: 636px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/newapp11.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/newapp11.png\" alt=\"Figure 1. Create a new Android application\" width=\"636\" height=\"543\" class=\"size-full wp-image-12549\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/newapp11.png 636w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/newapp11-300x256.png 300w\" sizes=\"(max-width: 636px) 100vw, 636px\" \/><\/a><figcaption id=\"caption-attachment-12549\" class=\"wp-caption-text\">Figure 1. Create a new Android application<\/figcaption><\/figure><\/p>\n<p>In the next window, the \u201cCreate Activity\u201d option should be checked. The new created activity will be the main activity of your project. Then press Next button.<\/p>\n<p><figure id=\"attachment_12550\" aria-describedby=\"caption-attachment-12550\" style=\"width: 636px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/newapp21.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/newapp21.png\" alt=\"Figure 2. Configure the project\" width=\"636\" height=\"543\" class=\"size-full wp-image-12550\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/newapp21.png 636w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/newapp21-300x256.png 300w\" sizes=\"(max-width: 636px) 100vw, 636px\" \/><\/a><figcaption id=\"caption-attachment-12550\" class=\"wp-caption-text\">Figure 2. Configure the project<\/figcaption><\/figure><\/p>\n<p>In \u201cConfigure Launcher Icon\u201d window you should choose the icon you want to have in your app. We will use the default icon of android, so click Next button.<\/p>\n<p>Select the \u201cBlank Activity\u201d option and press Next.<\/p>\n<p><figure id=\"attachment_11469\" aria-describedby=\"caption-attachment-11469\" style=\"width: 660px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/newproject_4.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/newproject_4.png\" alt=\"Figure 4. Create the activity and select its type\" width=\"660\" height=\"590\" class=\"size-full wp-image-11469\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/newproject_4.png 660w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/newproject_4-300x268.png 300w\" sizes=\"(max-width: 660px) 100vw, 660px\" \/><\/a><figcaption id=\"caption-attachment-11469\" class=\"wp-caption-text\">Figure 3. Create the activity and select its type<\/figcaption><\/figure><\/p>\n<p>You then have to specify a name for the new Activity and a name for the layout description of your app. The .xml files for the layout will automatically be created in the <code>res\/layout<\/code> folder. Finally, press Finish.<\/p>\n<p><figure id=\"attachment_11470\" aria-describedby=\"caption-attachment-11470\" style=\"width: 660px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/newproject_5.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/newproject_5.png\" alt=\"Figure 5. Create a new blank activity\" width=\"660\" height=\"590\" class=\"size-full wp-image-11470\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/newproject_5.png 660w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/07\/newproject_5-300x268.png 300w\" sizes=\"(max-width: 660px) 100vw, 660px\" \/><\/a><figcaption id=\"caption-attachment-11470\" class=\"wp-caption-text\">Figure 4. Create a new blank activity<\/figcaption><\/figure><\/p>\n<p>Here is the very final structure of the project, just in case you &#8216;ll miss something, while developing:<\/p>\n<p><figure id=\"attachment_12552\" aria-describedby=\"caption-attachment-12552\" style=\"width: 388px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/app_structure.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/app_structure.png\" alt=\"Figure 6. The final structure of the project\" width=\"388\" height=\"596\" class=\"size-full wp-image-12552\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/app_structure.png 388w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/app_structure-195x300.png 195w\" sizes=\"(max-width: 388px) 100vw, 388px\" \/><\/a><figcaption id=\"caption-attachment-12552\" class=\"wp-caption-text\">Figure 5. The final structure of the project<\/figcaption><\/figure><\/p>\n<h2><span id=\"code\">2. Creating the layout of the Main Activity<\/span><\/h2>\n<p>Let&#8217;s do it by opening <code>res\/layout\/activity_main.xml<\/code> and navigating to the respective xml tab and paste the following.<\/p>\n<p><span style=\"text-decoration: underline\"><i><code>activity_main.xml<\/code><\/i><br \/>\n<\/span><\/p>\n<pre class=\"brush:xml\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n&lt;LinearLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\nandroid:layout_width=\"fill_parent\"\nandroid:layout_height=\"fill_parent\"\nandroid:orientation=\"vertical\"\nandroid:background=\"#f5f5f5\" &gt;\n\n        &lt;ViewFlipper\n            android:id=\"@+id\/viewflipper\"\n            android:layout_width=\"fill_parent\"\n            android:layout_height=\"fill_parent\"\n            android:layout_margin=\"6dp\" &gt;\n            \n \t    \n            &lt;LinearLayout\n                android:layout_width=\"fill_parent\"\n                android:layout_height=\"fill_parent\"\n                android:gravity=\"center\"\n                android:orientation=\"vertical\" &gt;\n\n                &lt;TextView\n                \tandroid:layout_width=\"wrap_content\"\n                    android:layout_height=\"wrap_content\"\n                    android:layout_marginTop=\"15dp\"\n                    android:text=\"Windows PC\"\n                    android:textColor=\"#b7102f\"\n                    android:textSize=\"25dp\"&gt;\n                &lt;\/TextView&gt;\n\n                &lt;ImageView\n                \tandroid:layout_marginTop=\"15dp\"\n                    android:id=\"@+id\/imageView1\"\n                    android:layout_width=\"wrap_content\"\n                    android:layout_height=\"wrap_content\"\n                    android:src=\"@drawable\/windows_pc\" \/&gt;\n            &lt;\/LinearLayout&gt;\n            \n \t    \n        \t&lt;LinearLayout\n        \t    android:layout_width=\"fill_parent\"\n                android:layout_height=\"fill_parent\"\n                android:gravity=\"center\"\n                android:orientation=\"vertical\" &gt;\n\n                &lt;TextView\n                    android:layout_marginTop=\"15dp\"\n                    android:layout_width=\"wrap_content\"\n                    android:layout_height=\"wrap_content\"\n                    android:text=\"Ubuntu PC\"\n                    android:textColor=\"#191975\"\n                    android:textSize=\"25dp\"\n                    android:textStyle=\"italic\" &gt;\n                &lt;\/TextView&gt;\n\n                &lt;ImageView\n                    android:layout_marginTop=\"15dp\"\n                    android:id=\"@+id\/imageView2\"\n                    android:layout_width=\"wrap_content\"\n                    android:layout_height=\"wrap_content\"\n                    android:src=\"@drawable\/ubuntu_pc\" \/&gt;\n                    \n        \t&lt;\/LinearLayout&gt;\n        &lt;\/ViewFlipper&gt;\n&lt;\/LinearLayout&gt;\n<\/pre>\n<p>So, we selected a <code>LinearLayout<\/code> to hold our app&#8217;s UI and inside it a <code>ViewFlipper<\/code> element (lines 8-63), which has two children. We &#8216;ll follow the <code>LinearLayout<\/code> guidelines for the childrens&#8217; design, too, so each one of them will be declared into a linear layout.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>What we want our separate screens (ViewFlipper&#8217;s children) contain is an image and a corresponding <code>TextView<\/code>, declaring what the child has to do with.<\/p>\n<p>So, let&#8217;s associate our children with two operating systems that I mostly use, windows and ubuntu linux. What these children will hold, is the operating system&#8217;s <a href=\"http:\/\/developer.android.com\/reference\/android\/widget\/ImageView.html\" target=\"_blank\" rel=\"noopener noreferrer\"><code>ImageView<\/code><\/a> and a <code>TextView<\/code> that will make the animated navigation clearer.<\/p>\n<p>Simple as that, windows child is presented in lines 15-36, while ubuntu linux child, in lines 39-62.<\/p>\n<h2>3. Coding the Main Activity<\/h2>\n<p>Let&#8217;s first navigate to <code>src\/com.javacodegeeks.android.textviewtest\/MainActivity.java<\/code>. Next, complete the class like this:<\/p>\n<p><span style=\"text-decoration: underline\"><i><code>MainActivity.java<\/code><\/i><\/span><\/p>\n<pre class=\"brush:java; wrap-lines:false\">package com.javacodegeeks.android.viewflipperapp;\n\nimport android.app.Activity;\nimport android.os.Bundle;\nimport android.view.MotionEvent;\nimport android.widget.ViewFlipper;\n\npublic class MainActivity extends Activity {\n\tprivate ViewFlipper viewFlipper;\n    private float lastX;\n\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n    \tsuper.onCreate(savedInstanceState);\n        setContentView(R.layout.activity_main);\n        viewFlipper = (ViewFlipper) findViewById(R.id.viewflipper);\n    }\n\n    \/\/ Using the following method, we will handle all screen swaps.\n    public boolean onTouchEvent(MotionEvent touchevent) {\n    \tswitch (touchevent.getAction()) {\n        \n        case MotionEvent.ACTION_DOWN: \n        \tlastX = touchevent.getX();\n            break;\n        case MotionEvent.ACTION_UP: \n            float currentX = touchevent.getX();\n            \n            \/\/ Handling left to right screen swap.\n            if (lastX &lt; currentX) {\n            \t\n            \t\/\/ If there aren't any other children, just break.\n                if (viewFlipper.getDisplayedChild() == 0)\n                \tbreak;\n                \n                \/\/ Next screen comes in from left.\n                viewFlipper.setInAnimation(this, R.anim.slide_in_from_left);\n                \/\/ Current screen goes out from right. \n                viewFlipper.setOutAnimation(this, R.anim.slide_out_to_right);\n                \n                \/\/ Display next screen.\n                viewFlipper.showNext();\n             }\n                                     \n            \/\/ Handling right to left screen swap.\n             if (lastX &gt; currentX) {\n            \t \n            \t \/\/ If there is a child (to the left), kust break.\n            \t if (viewFlipper.getDisplayedChild() == 1)\n            \t\t break;\n    \n            \t \/\/ Next screen comes in from right.\n            \t viewFlipper.setInAnimation(this, R.anim.slide_in_from_right);\n            \t\/\/ Current screen goes out from left. \n            \t viewFlipper.setOutAnimation(this, R.anim.slide_out_to_left);\n                 \n            \t\/\/ Display previous screen.\n                 viewFlipper.showPrevious();\n             }\n             break;\n    \t }\n         return false;\n    }\n}\n<\/pre>\n<p>We first define <code>lastX<\/code> variable, which will be our guide, in order to manipulate easier the transaction between the available screens. How could we &#8220;fire&#8221; the beginning of such a transaction? I thought of a tab layout and a swype event, when I first asked myself this qusetion, so let&#8217;s give it a try to the second one, which is more user-friendly.[ulp id=&#8217;Ja8Orb5oPKdShcXt&#8217;]<\/p>\n<p>To get our <code>ViewFlipper<\/code>&#8216;s transactions done through swype event, we have to use <a href=\"http:\/\/developer.android.com\/reference\/android\/view\/MotionEvent.html\" target=\"_blank\" rel=\"noopener noreferrer\"><code>MotionEvent<\/code><\/a> class. Obviously, this is the specific part of our case, so let&#8217;s have a look at the standard one, too: <a href=\"http:\/\/developer.android.com\/training\/graphics\/opengl\/touch.html\" target=\"_blank\" rel=\"noopener noreferrer\"><code>onTouchEvent<\/code><\/a> is what we want to handle touch actions between our app and the user.<\/p>\n<p>The actual constants that we need from <code>MotionEvent<\/code> class, in order to implement the swype animation for our <code>ViewFlipper<\/code> element, are <code>ACTION_DOWN<\/code> and <code>ACTION_UP<\/code>. The first one indicates the initial starting location, while the second one, the final release location.<\/p>\n<p>According to the fore-mentioned words, we start tracking the location of a gesture using line 24. Nevertheless,  things get somehow more complicated when we have to code the <code>ACTION_UP<\/code> case, because we have to partition whether we have to do with a left-to-right gesture (lines 30-43) or with a right-to-left gesture (lines 46-59). Obviously, in each case we have to handle carefully the inherited  <code>setInAnimation<\/code> and <code>setOutAnimation<\/code> methods (we &#8216;ll talk in detail for the animation files attached on them, in the next section).<\/p>\n<h2>4. Coding the animations<\/h2>\n<p>This is how it goes:<\/p>\n<ul>\n<li>We want to implement two basic swype actions.<\/li>\n<li>Each one of them, has to be defined by two separate animation files, one to declare the direction from which the next screen is coming and the other to also declare the direction to which the current screen is getting hidden.<\/li>\n<li>This means that we &#8216;re actually in the need of four xml animation files, in overall.<\/li>\n<\/ul>\n<p>So, let&#8217;s create them in a new folder named &#8220;anim&#8221;, under the <code>res<\/code> (this means a relative path of <code>\/res\/anim\/<\/code>).<\/p>\n<p><span style=\"text-decoration: underline\"><i><code>slide_in_from_left.xml<\/code><\/i><br \/>\n<\/span><\/p>\n<pre class=\"brush:xml\">&lt;set xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    android:shareInterpolator=\"false\"&gt;\n    &lt;translate\n        android:fromXDelta=\"-100%\"\n        android:toXDelta=\"0%\"\n        android:fromYDelta=\"0%\"\n        android:toYDelta=\"0%\"\n        android:duration=\"1500\" \/&gt;\n&lt;\/set&gt;\n<\/pre>\n<p>This animation can be adapted to a screen that we want to enter our <code>ViewFlipper<\/code> element, from a hidden (-100% at X-axis) position and it matches a left-to-right gesture.<\/p>\n<p><span style=\"text-decoration: underline\"><i><code>slide_out_to_right.xml<\/code><\/i><br \/>\n<\/span><\/p>\n<pre class=\"brush:xml\">&lt;set xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    android:shareInterpolator=\"false\"&gt;\n      &lt;translate\n          android:fromXDelta=\"0%\"\n          android:toXDelta=\"100%\"\n          android:fromYDelta=\"0%\"\n          android:toYDelta=\"0%\"\n          android:duration=\"1500\"\/&gt;\n&lt;\/set&gt;\n<\/pre>\n<p>This animation can be adapted to a screen that we want to hide from our <code>ViewFlipper<\/code> element, from a visible (0% at X-axis) position and it matches a left-to-right gesture.<\/p>\n<p>The following two animations are similar to the two ones that are fore-mentioned, but these ones provide functionality regarding the right-to-left gesture.<\/p>\n<p><span style=\"text-decoration: underline\"><i><code>slide_in_from_right.xml<\/code><\/i><br \/>\n<\/span><\/p>\n<pre class=\"brush:xml\">&lt;set xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    android:shareInterpolator=\"false\"&gt;\n    &lt;translate\n        android:fromXDelta=\"100%\"\n        android:toXDelta=\"0%\"\n        android:fromYDelta=\"0%\"\n        android:toYDelta=\"0%\"\n        android:duration=\"1500\" \/&gt;\n&lt;\/set&gt;\n<\/pre>\n<p><span style=\"text-decoration: underline\"><i><code>slide_out_to_left.xml<\/code><\/i><br \/>\n<\/span><\/p>\n<pre class=\"brush:xml\">&lt;set xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    android:shareInterpolator=\"false\"&gt;\n    &lt;translate\n        android:fromXDelta=\"0%\"\n        android:toXDelta=\"-100%\"\n        android:fromYDelta=\"0%\"\n        android:toYDelta=\"0%\"\n        android:duration=\"1500\" \/&gt;\n&lt;\/set&gt;\n<\/pre>\n<p><i>For further questions, please refer to <a href=\"http:\/\/stackoverflow.com\/questions\/11504005\/how-does-translateanimation-works-android\" target=\"_blank\" rel=\"noopener noreferrer\">this<\/a> post.<\/i><\/p>\n<h2> Running the application<\/h2>\n<p>The initial screen is of course the first child of our <code>ViewFlipper<\/code>:<\/p>\n<p><figure id=\"attachment_12610\" aria-describedby=\"caption-attachment-12610\" style=\"width: 488px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/run_app1.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/run_app1.png\" alt=\"Figure 6. Initial state of the app\" width=\"488\" height=\"470\" class=\"size-full wp-image-12610\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/run_app1.png 488w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/run_app1-300x288.png 300w\" sizes=\"(max-width: 488px) 100vw, 488px\" \/><\/a><figcaption id=\"caption-attachment-12610\" class=\"wp-caption-text\">Figure 6. Initial state of the app<\/figcaption><\/figure><\/p>\n<p>Let&#8217;s make a right-to-left gesture!<\/p>\n<p><figure id=\"attachment_12613\" aria-describedby=\"caption-attachment-12613\" style=\"width: 488px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/run_app2.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/run_app2.png\" alt=\"Figure 7. Right-to-left gesture\" width=\"488\" height=\"470\" class=\"size-full wp-image-12613\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/run_app2.png 488w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/run_app2-300x288.png 300w\" sizes=\"(max-width: 488px) 100vw, 488px\" \/><\/a><figcaption id=\"caption-attachment-12613\" class=\"wp-caption-text\">Figure 7. Right-to-left gesture<\/figcaption><\/figure><\/p>\n<p>Obviously, if we now make a left-to-right gesture, the windows screen will come back.<\/p>\n<h2>6. Download the Eclipse Project<\/h2>\n<p>This was an example of ViewFlipper in Android.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here : <a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/08\/ViewFlipperApp.zip\"><b>ViewFlipperApp.zip<\/b><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>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 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 &hellip;<\/p>\n","protected":false},"author":12,"featured_media":1202,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[633],"tags":[1170],"class_list":["post-12542","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-viewflipper","tag-viewflipper"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Android ViewFlipper Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"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\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/viewflipper\/android-viewflipper-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Android ViewFlipper Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"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\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/viewflipper\/android-viewflipper-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/toubou.techblog\/\" \/>\n<meta property=\"article:published_time\" content=\"2014-08-05T08:00:53+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-04-24T13:04:49+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Thodoris Bais\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@ThodorisBais\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Thodoris Bais\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/viewflipper\/android-viewflipper-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/viewflipper\/android-viewflipper-example\/\"},\"author\":{\"name\":\"Thodoris Bais\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/045f5a70ed608824c16959f146ede983\"},\"headline\":\"Android ViewFlipper Example\",\"datePublished\":\"2014-08-05T08:00:53+00:00\",\"dateModified\":\"2019-04-24T13:04:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/viewflipper\/android-viewflipper-example\/\"},\"wordCount\":1017,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/viewflipper\/android-viewflipper-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\",\"keywords\":[\"ViewFlipper\"],\"articleSection\":[\"ViewFlipper\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/viewflipper\/android-viewflipper-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/viewflipper\/android-viewflipper-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/viewflipper\/android-viewflipper-example\/\",\"name\":\"Android ViewFlipper Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/viewflipper\/android-viewflipper-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/viewflipper\/android-viewflipper-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\",\"datePublished\":\"2014-08-05T08:00:53+00:00\",\"dateModified\":\"2019-04-24T13:04:49+00:00\",\"description\":\"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\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/viewflipper\/android-viewflipper-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/viewflipper\/android-viewflipper-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/viewflipper\/android-viewflipper-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/viewflipper\/android-viewflipper-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Android\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/android\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"core\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"widget\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/widget\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"ViewFlipper\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/widget\/viewflipper\/\"},{\"@type\":\"ListItem\",\"position\":6,\"name\":\"Android ViewFlipper Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/045f5a70ed608824c16959f146ede983\",\"name\":\"Thodoris Bais\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/03\/Thodoris-Bais_avatar_1425256492-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/03\/Thodoris-Bais_avatar_1425256492-96x96.jpg\",\"caption\":\"Thodoris Bais\"},\"description\":\"Thodoris is an Oracle Certified Associate Java Programmer and currently works as a Junior Software Developer, for Intrasoft International S.A. He holds a diploma at Informatics &amp; Telecommunications Engineering and is interested in continuous development.\",\"sameAs\":[\"http:\/\/thodorisbais.blogspot.com\",\"https:\/\/www.facebook.com\/toubou.techblog\/\",\"https:\/\/instagram.com\/thodoris.bais\/\",\"https:\/\/www.linkedin.com\/pub\/thodoris-bais\/69\/6b7\/408\",\"https:\/\/x.com\/@ThodorisBais\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/thodoris-bais\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Android ViewFlipper Example - Java Code Geeks","description":"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","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/viewflipper\/android-viewflipper-example\/","og_locale":"en_US","og_type":"article","og_title":"Android ViewFlipper Example - Java Code Geeks","og_description":"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","og_url":"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/viewflipper\/android-viewflipper-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_author":"https:\/\/www.facebook.com\/toubou.techblog\/","article_published_time":"2014-08-05T08:00:53+00:00","article_modified_time":"2019-04-24T13:04:49+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","type":"image\/jpeg"}],"author":"Thodoris Bais","twitter_card":"summary_large_image","twitter_creator":"@ThodorisBais","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Thodoris Bais","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/viewflipper\/android-viewflipper-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/viewflipper\/android-viewflipper-example\/"},"author":{"name":"Thodoris Bais","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/045f5a70ed608824c16959f146ede983"},"headline":"Android ViewFlipper Example","datePublished":"2014-08-05T08:00:53+00:00","dateModified":"2019-04-24T13:04:49+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/viewflipper\/android-viewflipper-example\/"},"wordCount":1017,"commentCount":1,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/viewflipper\/android-viewflipper-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","keywords":["ViewFlipper"],"articleSection":["ViewFlipper"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/viewflipper\/android-viewflipper-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/viewflipper\/android-viewflipper-example\/","url":"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/viewflipper\/android-viewflipper-example\/","name":"Android ViewFlipper Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/viewflipper\/android-viewflipper-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/viewflipper\/android-viewflipper-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","datePublished":"2014-08-05T08:00:53+00:00","dateModified":"2019-04-24T13:04:49+00:00","description":"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","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/viewflipper\/android-viewflipper-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/viewflipper\/android-viewflipper-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/viewflipper\/android-viewflipper-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/viewflipper\/android-viewflipper-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Android","item":"https:\/\/examples.javacodegeeks.com\/category\/android\/"},{"@type":"ListItem","position":3,"name":"core","item":"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/"},{"@type":"ListItem","position":4,"name":"widget","item":"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/widget\/"},{"@type":"ListItem","position":5,"name":"ViewFlipper","item":"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/widget\/viewflipper\/"},{"@type":"ListItem","position":6,"name":"Android ViewFlipper Example"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/045f5a70ed608824c16959f146ede983","name":"Thodoris Bais","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/03\/Thodoris-Bais_avatar_1425256492-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/03\/Thodoris-Bais_avatar_1425256492-96x96.jpg","caption":"Thodoris Bais"},"description":"Thodoris is an Oracle Certified Associate Java Programmer and currently works as a Junior Software Developer, for Intrasoft International S.A. He holds a diploma at Informatics &amp; Telecommunications Engineering and is interested in continuous development.","sameAs":["http:\/\/thodorisbais.blogspot.com","https:\/\/www.facebook.com\/toubou.techblog\/","https:\/\/instagram.com\/thodoris.bais\/","https:\/\/www.linkedin.com\/pub\/thodoris-bais\/69\/6b7\/408","https:\/\/x.com\/@ThodorisBais"],"url":"https:\/\/examples.javacodegeeks.com\/author\/thodoris-bais\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/12542","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=12542"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/12542\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1202"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=12542"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=12542"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=12542"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}