user interface - Can I change the behavior of Android's LayoutTransition to eliminate the fade but keep the height animation? -


it's easy add layout transitions attribute:

android:animatelayoutchanges="true"  

however, animation not create pleasing user experience. when elements added layout (i'm using simple vertical linearlayout) or change gone visible there's 2-stage process think rather annoying. first, room prepared new element (everything else pushed down). when there's enough room, new view fades existence. likewise, when view removed or changes visible gone, first fades out, room claimed gradually shrinks zero.

i way change animation think natural way it: when adding view height gradually changes 0 full size, first see top, without ever changing alpha. when removing view height gradually changes full size zero, near end of animation see top, without ever changing alpha.

how can accomplish in android? (note: user can tap on several buttons , cause several elements appear / disappear in quick succession, before animation other views ended - or make appear while it's still appearing).

another question perhaps not place ask: why isn't default?

(and if it's possible, can different behavior specified in first bottom of view appears, rather top, new view slides down under 1 above it?)

you have write own animator , set it. code:

 final viewgroup profileparent = (viewgroup) view.findviewbyid(r.id.profileparent);     layouttransition transition = new layouttransition();     animator appearinganimation = objectanimator.offloat(null, "translationy", 600/*profileparent.getheight()*/, 0);     appearinganimation.addlistener(new animatorlisteneradapter() {         public void onanimationend(animator anim) {             view view = (view) ((objectanimator) anim).gettarget();             view.settranslationy(0f);         }     });     animator disappearinganimation = objectanimator.offloat(null, "translationy", 0, 600/*profileparent.getheight()*/);     appearinganimation.addlistener(new animatorlisteneradapter() {         public void onanimationend(animator anim) {             view view = (view) ((objectanimator) anim).gettarget();             view.settranslationy(0f);         }     });     transition.setanimator(layouttransition.appearing, appearinganimation);     transition.setduration(layouttransition.appearing, 300);     transition.setstartdelay(layouttransition.appearing, 0);      transition.setanimator(layouttransition.disappearing, disappearinganimation);     transition.setduration(layouttransition.disappearing, 300);     transition.setstartdelay(layouttransition.disappearing, 0);      profileparent.setlayouttransition(transition); 

Popular posts from this blog