Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude certain elements from being animated in android layout transitions

I have a question regarding the android layout transition framework. In particular i want to achieve an effect that a certain part of an layout slides down or up depending on the visibility of another view(s).

Imagine the following layout. (And please overlook the nested LinearLayouts here ;) )

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:animateLayoutChanges="true">

    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        <View
                android:id="@+id/changingView1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:visibility="gone"/>

        <View
                android:id="@+id/changingView2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:visibility="gone"/>

    </LinearLayout>

    <LinearLayout
            android:id="@+id/movingView"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:animateLayoutChanges="false"/>

</LinearLayout>

Now what i want to achieve is that when changingView1 and changingView2 change their visibility that movingView slides up or down.

By enabling the LayoutTransition.CHANGING for the parent layout the sliding part works fine so. But this has the side effect that the movingView will also be animated when there are being items added or removed because this layout changes its bounds. And here lies my problem because this results in a very strange looking animation.

So back to my question. Is there a way to keep the sliding animation without animating layout bound changes on the movingView?

Disabling layoutTransitions on the movingView obviously does not help because this only effects the animations of the child views. I also tried playing around with enabling and disabling different LayoutTransitions on the parent layout but so far without the desired effect.

If i can add more details please let me know otherwise i hope someone can help me out.

Thanks in advance!

like image 417
Felix Avatar asked Aug 18 '16 09:08

Felix


1 Answers

I know it's late but hope it can help someone. Since android:animateLayoutChanges is the property of the direct parent, you can wrap your View/Layout in a FrameLayout (or some other ViewGroup) and set android:animateLayoutChanges="false" on the new parent.

like image 114
Sir Codesalot Avatar answered Nov 08 '22 08:11

Sir Codesalot