So im trying to animate when i set the visibility of a linearlayout with other widgets, from GONE to VISIBLE and the opposite.Im using togglebuttons to show and hide. Here\'s an
Like tomash said before: There's no easy way.
You might want to take a look at my answer here.
It explains how to realize a sliding (dimension changing) view.
In this case it was a left and right view: Left expanding, right disappearing.
It's might not do exactly what you need but with inventive spirit you can make it work ;)
This is a quite old question, still comments show, that still people have problems, so here is my solution with following additional features:
CoordinatorLayout
Function - Example (I have this function in an utility class)
public static void animateViewVisibility(final View view, final int visibility)
{
// cancel runnning animations and remove and listeners
view.animate().cancel();
view.animate().setListener(null);
// animate making view visible
if (visibility == View.VISIBLE)
{
view.animate().alpha(1f).start();
view.setVisibility(View.VISIBLE);
}
// animate making view hidden (HIDDEN or INVISIBLE)
else
{
view.animate().setListener(new AnimatorListenerAdapter()
{
@Override
public void onAnimationEnd(Animator animation)
{
view.setVisibility(visibility);
}
}).alpha(0f).start();
}
}
Adjust animation
After calling view.animate()
you can adjust the animation to whatever you want (set duration, set interpolator and more...). You may as well hide a view by scaling it instead of adjusting it's alpha value, just replace the alpha(...)
with scaleX(...)
or scaleY(...)
in the utility method if you want that