Search code examples
androidanimationinterpolationviewflipper

Interpolator for ViewFlipper


What interpolator should I use for a viewflipper that contains some images to see the images continuous, I mean to see the end of the image that goes to left and the the begin of the image that come from right? (sorry for my description, I hope you understand what I mean to say). I use animation (to left and to right) for viewflipper but the images come appear alone and it is not continuous.

Have anyone any idea what should be the solution?


Solution

  • Try the following:

    Setting up your ViewFlipper:

        ViewFlipper flipper = (ViewFlipper) findViewById(R.id.flipper);
        flipper.setInAnimation(this, R.anim.in);
        flipper.setOutAnimation(this, R.anim.out);
        flipper.startFlipping();
    

    from layout XML:

    <ViewFlipper 
        android:id="@+id/flipper"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:flipInterval="2000">
        <ImageView...
        .../>
    </ViewFlipper>
    

    Animations:
    in.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <translate  xmlns:android="http://schemas.android.com/apk/res/android"
        android:interpolator="@android:anim/linear_interpolator"
        android:fromXDelta="-100%" android:toXDelta="0" android:duration="150"/>
    

    out.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <translate  xmlns:android="http://schemas.android.com/apk/res/android"
        android:interpolator="@android:anim/linear_interpolator"
        android:fromXDelta="0" android:toXDelta="100%" android:duration="150"/>