Search code examples
androidanimationandroid-linearlayoutobjectanimator

Android animation linearlayout


I have got a linearlayout form. This form has got a 2 fields. I would like get this effect:

Two fields, one is hidden (under top bar). When i click button 'ok' this linear layout go down and display next field (hidden field). How get this effect?

enter image description here


Solution

    • Place your two fields inside a RelativeLayout.
    • Set the property android:visibility="gone" for the first of them.
    • Set the property android:layout_below="@id/yourFirstField" for the second.
    • Add onClickListener to the button and, in the body on the listener in your Java class, change the visibility of the first field to visible (I guess it's an EditText, so EditText.VISIBLE)
    • If you want to get a nice effect for hiding/showing elements, add android:animateLayoutChanges="true" to your RelativeLayout (the container of both items).

    This should work!! I hope this helps!!