Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android:animateLayoutChanges won't work in parent layout

Suppose I have a layout file structured like this:

<LinearLayout android:id="@+id/main" android:orientation="vertical" android:animateLayoutChanges="true">
    <EditText>

    <TextView android:id="@+id/header1">
    <LinearLayout android:id="@+id/insertionPoint" android:orientation="vertical" android:animateLayoutChanges="true">
    </LinearLayout>

    <TextView android:id="@+id/header2">
</LinearLayout>

I want to dynamically add text fields to the Layout insertionPoint and I would like to see an animation of the elements below it (in this case, header2) sliding down.

Using android:animateLayoutChanges only animates the elements in the layout insertionPoint, so there is no animation for header2. What should I do?

Just to be more clear: what I would like to do here is something like the animations that we can see in the People app in ICS when we add more fields, like telephone numbers, to a contact.

Thank you!

like image 718
Victor Araújo Avatar asked Jul 30 '12 04:07

Victor Araújo


1 Answers

API 16 added the LayoutTransition.CHANGING animation type, however it is disabled by default.

To enable:

LinearLayout linearLayout = (LinearLayout) findViewById(R.id.main);
linearLayout.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);

Nice DevBytes video: https://www.youtube.com/watch?v=55wLsaWpQ4g

like image 131
tachyonflux Avatar answered Oct 26 '22 15:10

tachyonflux