![ViewFlipper with Animation ViewFlipper with Animation](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjg_1YIpjNXm7jZd4tQTWHNGDvXqp5YaMiiiAAaIpPB7PZ8wUxAG0WIbf_8HJrIqQKmoPskSrW9nvgZZlJasOlPCzYBlxQckYefL9Z6Y5bc-xO63nxFF3QMcg1dRdds8l4xcsvh4JS2lKSG/s400/ViewFlipper_01.png)
![ViewFlipper with Animation ViewFlipper with Animation](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjglKznJ59w2cOkjUEruWrcZoXofzIt2uHSUBTXl-IqEKydSgZ9tBTii6ZESenZefMtyPoOzds-s6Dwe9IhWit8jr5X0nO4_TR-aruAoqYHCz64_lU8GuX2q30p_ATrv4lxhGy_TwdmctzJ/s400/ViewFlipper_02.png)
![ViewFlipper with Animation ViewFlipper with Animation](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFBw0h5FBQOwVwohuEb5VDmKgc8uxFWfEmY1EO3dOElSghfxERy9LiV2ub17xIKWlyHWbZ6o2hgFOV_v57HPsvnH6t0DbtfCvJ4xTiI5rLQ0LXEFoHHBxnM-8Huqxi9okSwkOJRXBdjSKm/s400/ViewFlipper_03.png)
create four XML file for the animation in /res/anim folder
/res/anim/flipinnext.xml
1 2 3 4 5 6 7 8 9 | <? xml version = "1.0" encoding = "utf-8" ?> android:interpolator = "@android:anim/decelerate_interpolator" > < translate android:fromXDelta = "-100%" android:toXDelta = "0%" android:duration = "500" /> </ set > |
/res/anim/flipoutnext.xml
1 2 3 4 5 6 7 8 9 | <? xml version = "1.0" encoding = "utf-8" ?> android:interpolator = "@android:anim/decelerate_interpolator" > < translate android:fromXDelta = "0%" android:toXDelta = "100%" android:duration = "500" /> </ set > |
/res/anim/flipinprevious.xml
1 2 3 4 5 6 7 8 9 | <? xml version = "1.0" encoding = "utf-8" ?> android:interpolator = "@android:anim/decelerate_interpolator" > < translate android:fromXDelta = "100%" android:toXDelta = "0%" android:duration = "500" /> </ set > |
/res/anim/flipoutprevious.xml
1 2 3 4 5 6 7 8 9 | <? xml version = "1.0" encoding = "utf-8" ?> android:interpolator = "@android:anim/decelerate_interpolator" > < translate android:fromXDelta = "0%" android:toXDelta = "-100%" android:duration = "500" /> </ set > |
/res/layout/main.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | <? xml version = "1.0" encoding = "utf-8" ?> android:orientation = "vertical" android:layout_width = "fill_parent" android:layout_height = "fill_parent" > < TextView android:layout_width = "fill_parent" android:layout_height = "wrap_content" android:text = "@string/hello" /> < Button android:id = "@+id/flipnext" android:layout_width = "fill_parent" android:layout_height = "wrap_content" android:text = "Flip Next" /> < Button android:id = "@+id/flipprevious" android:layout_width = "fill_parent" android:layout_height = "wrap_content" android:text = "Flip Previous" /> < ViewFlipper android:id = "@+id/viewflipper" android:layout_width = "fill_parent" android:layout_height = "fill_parent" > < LinearLayout android:layout_width = "fill_parent" android:layout_height = "fill_parent" android:orientation = "vertical" > < TextView android:layout_width = "fill_parent" android:layout_height = "wrap_content" android:text = "First Screen" /> < ImageView android:layout_width = "fill_parent" android:layout_height = "fill_parent" android:src = "@drawable/icon" /> </ LinearLayout > < LinearLayout android:layout_width = "fill_parent" android:layout_height = "fill_parent" android:orientation = "vertical" > < TextView android:layout_width = "fill_parent" android:layout_height = "wrap_content" android:text = "Second Screen" /> < Button android:layout_width = "fill_parent" android:layout_height = "fill_parent" android:text = "Big Big Button" /> </ LinearLayout > < LinearLayout android:layout_width = "fill_parent" android:layout_height = "fill_parent" android:orientation = "vertical" > < TextView android:layout_width = "fill_parent" android:layout_height = "wrap_content" android:text = "Third Screen" /> < Button android:layout_width = "fill_parent" android:layout_height = "wrap_content" android:text = "Normal Button" /> < Button android:layout_width = "fill_parent" android:layout_height = "wrap_content" android:text = "Normal Button" /> < Button android:layout_width = "fill_parent" android:layout_height = "wrap_content" android:text = "Normal Button" /> </ LinearLayout > </ ViewFlipper > </ LinearLayout > |
main java code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | package com.MyViewFlipper; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.Button; import android.widget.ViewFlipper; public class MyViewFlipper extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.main); Button buttonFlipNext = (Button)findViewById(R.id.flipnext); Button buttonFlipPrevious = (Button)findViewById(R.id.flipprevious); final ViewFlipper viewFlipper = (ViewFlipper)findViewById(R.id.viewflipper); final Animation animFlipInNext = AnimationUtils.loadAnimation( this , R.anim.flipinnext); final Animation animFlipOutNext = AnimationUtils.loadAnimation( this , R.anim.flipoutnext); final Animation animFlipInPrevious = AnimationUtils.loadAnimation( this , R.anim.flipinprevious); final Animation animFlipOutPrevious = AnimationUtils.loadAnimation( this , R.anim.flipoutprevious); buttonFlipNext.setOnClickListener( new Button.OnClickListener(){ @Override public void onClick(View arg0) { // TODO Auto-generated method stub viewFlipper.setInAnimation(animFlipInNext); viewFlipper.setOutAnimation(animFlipOutNext); viewFlipper.showNext(); }}); buttonFlipPrevious.setOnClickListener( new Button.OnClickListener(){ @Override public void onClick(View arg0) { // TODO Auto-generated method stub viewFlipper.setInAnimation(animFlipInPrevious); viewFlipper.setOutAnimation(animFlipOutPrevious); viewFlipper.showPrevious(); }}); } } |
No comments:
Post a Comment