WonderCsabo
WonderCsabo

Reputation: 12207

Wait for other view animation end

I have the following layout snippet:

    <LinearLayout
        android:id="@+id/tagContainer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:animateLayoutChanges="true" >

    </LinearLayout>

    <TextView
        android:id="@+id/commentLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tagContainer" />

As you can see, animateLayoutChanges is set to true on the LinearLayout, so when an item is added to it, it animates the addition. This ok, but there are problems with the removal. If i remove an item, the animation still plays well, but the TextView below pops up immediately and does not wait for the animation to finish. How can i achieve this, or even better, make the TextView animate up synchronized with the LinearLayout animation?

Upvotes: 12

Views: 6741

Answers (2)

18446744073709551615
18446744073709551615

Reputation: 16832

This is not an answer but a ready-to use code snippet that you may try to examine what is happening.

mContainer = (ViewGroup) v.findViewById(R.id.container);
if (Build.VERSION.SDK_INT >= 11) {
    mLayoutTransition = mContainer.getLayoutTransition();

    if (mLayoutTransition != null) {
        mLayoutTransition.addTransitionListener(new LayoutTransition.TransitionListener() {

            @Override
            public void startTransition(LayoutTransition transition, ViewGroup container, View view, int transitionType) {
                Log.d("\n\n startTransition: in "+container+" view "+view+" type "+ descr(transitionType));
            }

            @Override
            public void endTransition(LayoutTransition transition, ViewGroup container, View view, int transitionType) {
                Log.d("\n\n endTransition: in "+container+" view "+view+" type "+ descr(transitionType));
            }

            String descr(int transitionType) {
                String[] m = new String[]{"CHANGE_APPEARING","CHANGE_DISAPPEARING","APPEARING","DISAPPEARING"};
                return "" + transitionType + ": " + m[transitionType&3] + " changing="+( transitionType&LayoutTransition.CHANGING);
            }
        });
    }
}

For me, the container view is a LinearLayout and the event of interest is:

public void endTransition(LayoutTransition transition, ViewGroup container, View view, int transitionType) { // UI thread
    if (transitionType == LayoutTransition.DISAPPEARING) {
        // start 2nd animation, it will be done while another view is moved
    }
}

Upvotes: 2

Nikola Despotoski
Nikola Despotoski

Reputation: 50538

You can retrieve the LayoutTransition from the view in following way:

mLinearLayout = findViewById(R.id.myLayout);
LayoutTransition layoutTransition = mLinearLayout.getLayoutTransition();
layoutTransition.addTransitionListener(new TransitionListener(){

            @Override
            public void endTransition(LayoutTransition arg0, ViewGroup arg1,
                    View arg2, int arg3) {
                switch(arg2.getId()){
                                //....
                                }
            }

            @Override
            public void startTransition(LayoutTransition transition,
                    ViewGroup container, View view, int transitionType) {
                switch(view.getId()){
                                //....
                                }

            }});

Upvotes: 25

Related Questions