android - Why does my layout view animate its size before its sibling has changed its size? -


i have simple layout 4 linearlayout groups each holding different type of view. trying start off screen have linearlayouts "collapsed" turning child's visibility view.gone. on each layout, layout's parent, have android:animatelayoutchanges="true" when click on layout (which set clickable), child have visibility set view.visible, expanding parent linearlayout nicely.

all works fine when set visibility view.visible, when click again, set view.gone linearlayout shrink.

the problem facing when shrinks, seems linearlayout's height gets updated before has time start animating, siblings below animate upwards immediately, looking quick bad.

here small animation of what's going on:

enter image description here

i can tell child (the datepicker) starts fade out when set visibility view.gone.

here code show how approaching (irrelevant items left out):

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:id="@+id/layoutmain"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:clipchildren="false"     tools:context=".quickaddmain">      <scrollview         android:id="@+id/scrollview"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:clipchildren="false">          <relativelayout             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:animatelayoutchanges="true"             android:clipchildren="false"             android:orientation="vertical">          <linearlayout                 android:id="@+id/testgroup03"                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:layout_marginbottom="5dp"                 android:layout_marginleft="10dp"                 android:layout_marginright="10dp"                 android:layout_margintop="5dp"                 android:animatelayoutchanges="true"                 android:background="@drawable/section_background"                 android:orientation="vertical">                  <linearlayout                     android:id="@+id/testtitle03clickable"                     android:layout_width="match_parent"                     android:layout_height="wrap_content"                     android:background="?android:selectableitembackground"                     android:clickable="true">                      <textview                         android:id="@+id/testtitle03"                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:layout_marginbottom="10dp"                         android:layout_marginleft="10dp"                         android:layout_margintop="5dp"                         android:text="test title 03"                         android:textappearance="?android:attr/textappearancemedium"                         android:textstyle="bold" />                  </linearlayout>                  <datepicker                     android:id="@+id/datepicker"                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:layout_gravity="center_horizontal"                     android:calendarviewshown="false"                     android:datepickermode="spinner"                     android:visibility="gone" />             </linearlayout>              <linearlayout                 android:id="@+id/testgroup04"                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:layout_marginbottom="70dp"                 android:layout_marginleft="10dp"                 android:layout_marginright="10dp"                 android:layout_margintop="5dp"                 android:animatelayoutchanges="true"                 android:background="@drawable/section_background"                 android:orientation="vertical"                 android:layout_below="@+id/dategroup">                  <linearlayout                     android:id="@+id/testtitle04clickable"                     android:layout_width="match_parent"                     android:layout_height="wrap_content"                     android:background="?android:selectableitembackground"                     android:clickable="true">                      <textview                         android:id="@+id/testtitle04"                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:layout_marginbottom="10dp"                         android:layout_marginleft="10dp"                         android:layout_margintop="5dp"                         android:text="test title 04"                         android:textappearance="?android:attr/textappearancemedium"                         android:textstyle="bold" />                  </linearlayout>                  <timepicker                     android:id="@+id/timepicker"                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:layout_gravity="center_horizontal"                     android:timepickermode="spinner"                     android:visibility="gone" />             </linearlayout>          </relativelayout>     </scrollview> 

java:

layouttransition layouttransition;  layouttransition = dategroup.getlayouttransition(); layouttransition.enabletransitiontype(layouttransition.changing);  layouttransition = timegroup.getlayouttransition(); layouttransition.enabletransitiontype(layouttransition.changing); 

    dateactivation = (linearlayout) findviewbyid(r.id.dateactivation);     dateactivation.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             if (datepicker.getvisibility() == view.gone) {                 datepicker.setvisibility(view.visible);             } else {                 datepicker.setvisibility(view.gone);             }         }     });      timeactivation = (linearlayout) findviewbyid(r.id.timeactivation);     timeactivation.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             if (timepicker.getvisibility() == view.gone) {                 timepicker.setvisibility(view.visible);             } else {                 timepicker.setvisibility(view.gone);             }         }     }); 

please let me know if i'm missing or if needs clarified. thanks.


Comments