Android ViewAnimator : animation while changing viewstub child

3.7k views Asked by At

Here's my problem :

I've got a ViewAnimator like :

<ViewAnimator
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/viewanimator">

    <ViewStub
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/form_viewstub"
        android:inflatedId="@+id/form_view"
        android:layout="@layout/form_layout"/>

    <ViewStub
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/history_viewstub"
        android:inflatedId="@+id/history_view"
        android:layout="@layout/history_layout"/>

    <ViewStub
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/call_viewstub"
        android:inflatedId="@+id/call_view"
        android:layout="@layout/call_layout"/>

</ViewAnimator>

When I'm animating a viewstub that is after the current, there is no problem. The problem is that when I try to animate a viewstub before, I can't see the animation. Here's a concrete example :

When I try to animate id/history_viewstub with the following animation and id/call_viewstub is the current displayed layout I do not see anything (I imagine that the animation is played behin the current view)

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <scale
        android:interpolator="@android:anim/accelerate_interpolator"
        android:fromXScale="0.0"
        android:toXScale="1.0"
        android:fromYScale="0.0"
        android:toYScale="1.0"
        android:pivotX="1.0"
        android:pivotY="0.0"
        android:fillAfter="true"
        android:duration="600"/>
    <translate
        android:fromXDelta="100%"
        android:toXDelta="0"
        android:duration="600"/>
</set>

Anybody has already faced this problem ?

Is there a way to specify a z-index to the viewstubs like in web development ?


Edit

Using the ZAdjustment property doesn't correct the problem

3

There are 3 answers

2
Gil On

It seems to me that you are not actually using the functionality of the ViewAnimator class but rather just the inherited FrameLayout class.

To animate view transitions you need to set the android:inAnimation and android:outAnimation properties on the ViewAnimator and initiate the transitions from your code using either setDisplayedChild() or showNext() and showPrevious().

0
mig35 On

You can use this View.bringToFront.

This method will move your view to the end of the childs list. So its and other views index will change. Be careful about this.

3
areyling On

I'm sure you've already solved this problem, but since there isn't an answer...you should be able to use android:zAdjustment="top".