简体   繁体   English

动画元素从消失变为可见(而不是从不可见)

[英]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. 我想淡入一个元素,但是要以某种方式将其隐藏( GONE )变为可见,以这种方式移开元素。 The animation I am currently using is the AlphaAnimation 我当前使用的动画是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 . 但这只会使它从INVSIBLE变为VISIBLE ,我想要的是将它从GONE变为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. GONE和INVISIBLE之间的区别在于,当视图为INVISIBLE时,布局仍将其视为在那里,而GONE会导致布局发生更改。 Thus, animating an alpha from GONE to VISIBLE doesn't make really make sense. 因此,从GONE到VISIBLE设置Alpha动画没有任何意义。

Android gives you a reasonably good animation out of the box. Android为您提供了相当不错的动画效果。 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. 因此,只需将视图的可见性从GONE设置为VISIBLE即可自动开始。

<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. 有关更多信息,请参见http://developer.android.com/training/animation/layout.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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