简体   繁体   中英

Animate element from Gone to Visible (rather than from Invisible)

I want to fade in an element, but in a way that it is hidden ( GONE ) into visible, moving away the elements in the way. The animation I am currently using is the AlphaAnimation

Animation fadeIn = new AlphaAnimation(0, 1);
fadeIn.setInterpolator(new DecelerateInterpolator());
fadeIn.setDuration(2000);

but this only animates it from INVSIBLE to VISIBLE , what I want is to animate it from GONE to VISIBLE .

Is this even possible or do I have to make this more complicated by animating the surrounding elements?

The difference between GONE and INVISIBLE is that when the view is INVISIBLE the layout still treats it as there, where as GONE causes the layout to change. Thus, animating an alpha from GONE to VISIBLE doesn't make really make sense.

Android gives you a reasonably good animation out of the box. You just tell it to animate layout changes for you. So simply setting the view's visibility from GONE to VISIBLE will automatically kick this off.

<LinearLayout android:id="@+id/container"
    android:animateLayoutChanges="true"
    ...
/>

As it happens, this animation slides the other components apart to make room, then fades in the view in question, so might be what you're after anyway.

See http://developer.android.com/training/animation/layout.html for more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM