I want to display banner(images moving in x direction) in my application. For that i am using ViewFlipper with Translation animation. Please find my below code..
my layout: banner.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ViewFlipper
android:id="@+id/banner_image"
android:layout_width="match_parent"
android:layout_height="258dp" />
</RelativeLayout>
In animation: in_from_right.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<translate
android:duration="3000"
android:fromXDelta="100%"
android:fromYDelta="0%"
android:toXDelta="0%"
android:toYDelta="0%" />
</set>
Out Animation: out_to_left.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate android:fromXDelta="0%" android:toXDelta="-100%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="3000"/>
</set>
My Java Code
public class BannerView extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.banner);
ViewFlipper myViewFlipper = (ViewFlipper) findViewById(R.id.banner_image);
//Setting first image in viewFlipper
ImageView imageView1 = new ImageView(HomeView.this);
imageView1.setImageDrawable(getResources().getDrawable(R.drawable.img1));
myViewFlipper.addView(imageView1);
//Setting second image in viewFlipper
ImageView imageView2 = new ImageView(HomeView.this);
imageView2.setImageDrawable(getResources().getDrawable(R.drawable.img2));
myViewFlipper.addView(imageView2);
myViewFlipper.setAutoStart(true);
//Setting in and out animation
myViewFlipper.setInAnimation(HomeView.this,R.anim.in_from_right);
myViewFlipper.setOutAnimation(HomeView.this,R.anim.out_to_left);
//Starting the view filpper to rotate
myViewFlipper.startFlipping();
}
}
Here my problem is,
When i set the duration for in and out animation as "5000", ViewFilpper's behavior is changing like the below,
Image start to move slowly and ending quickly.
I dont know where i am missing. I want to slow down the speed. Please help me resolve the issue.
Thanks for your reply. I found the solution for my problem. Please find my answer below.
I have changed my interpolator in xml as below:
And then i used android:flipInterval="5000" in my viewflipper solved my problem.