Search code examples
androidandroid-layoutviewflipperandroid-animationandroid-xml

ViewFlipper stacks child views on 'outAnimation'


I have a viewFlipper which flips between many textViews. For some reason the views stack on outAnimation. instead of just one performing 'in animation' and one performing 'out animation' I got one performing 'in animation' and all previous views performing 'out animation', Can somebody help me achieve a state where views dont stack upon each other on out animation?

Here is the flipper xml:

<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:id="@+id/viewFlipper1"      
        android:background="#60000000"
        android:inAnimation="@anim/flipper_transition_in"
        android:outAnimation="@anim/flipper_transition_out"
        android:autoStart="true"
        android:flipInterval="5000">

        <TextView  android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:textSize="20sp"
            android:text="אין דבר העומד בפני הרצון"
            android:textStyle="bold"
            android:gravity="center"
            android:textColor="#00ff00"
            android:singleLine="true"
            >
            </TextView> 

        <TextView  android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:textSize="20sp"
            android:text="קשה – זאת אומרת אפשר"
            android:textStyle="bold"
            android:gravity="center"
            android:textColor="#00ff00"
            android:singleLine="true"
            >
            </TextView>
        <TextView  android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:textSize="20sp"
            android:text="מי שלא מעז – לא מצליח"
            android:textStyle="bold"
            android:gravity="center"
            android:textColor="#00ff00"
            android:singleLine="true"
            >
            </TextView>
        <TextView  android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:textSize="20sp"
            android:text="אל תצפה לזה - תעבוד בשביל זה"
            android:textStyle="bold"
            android:gravity="center"
            android:textColor="#00ff00"
            android:singleLine="true"
            >
            </TextView>
        <TextView  android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:textSize="20sp"
            android:text="אל תוותר על מה שאתה רוצה"
            android:textStyle="bold"
            android:gravity="center"
            android:textColor="#00ff00"
            android:singleLine="true"
            >
            </TextView>
        <TextView  android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:textSize="20sp"
            android:text="דברים גדולים דורשים זמן"
            android:textStyle="bold"
            android:gravity="center"
            android:textColor="#00ff00"
            android:singleLine="true"
            >
            </TextView>     
        <TextView  android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:textSize="20sp"
            android:text="כשתגיע לשם תצחק על כולם"
            android:textStyle="bold"
            android:gravity="center"
            android:textColor="#00ff00"
            android:singleLine="true"
            >
            </TextView>

And here are the animation xmls:

in animation:

 <set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
>
 <translate android:fromXDelta="-100%p" android:toXDelta="0" android:duration="5000"/> 

out animation:

 <set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator"
    >
 <translate android:fromXDelta="0" android:toXDelta="100%p" android:duration="5000"/>

notice my animation translates the text from left to right, this is what i need, not a mistake. any help would be greatly appreciated!!! thanks in advance!


Solution

  • Hey your code seems to work. I did make a small change in the viewflipper tag.

    <ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:id="@+id/viewFlipper1" android:background="#60000000"
        android:inAnimation="@android:anim/slide_in_left" 
        android:outAnimation="@android:anim/slide_out_right"
        android:autoStart="true" android:flipInterval="5000">
    

    Instead of using the animation code you wrote, I used the animation in the android sdk. Btw your code doesn't have an end viewflipper tag. And instead of using use . You are not enclosing anything so the end tag isn't really necessary.