写了一个小程序,其中有一段处理是否有网络连接的代码,当判断网络无连接时,
就把原来显示网络无连接的那个view设置为visible,设定了一个固定的显示时间,
到了这个时间就使用一个AnimationSet,同时设置view的属性为gone,让它显示,
下次又到了无网络的情况下,显示网络无连接的这个view确不会显示,去判断是否可见
的结果却又是可见的,而且在固定的时候之后,又可以看到消失的动画效果,这个
AnimationSet是多个view共用的,当不使用这个AnimationSet时,就没这个问题,
AnimationSet的代码如下:/* 设置动画效果 */
animationSet = new AnimationSet(true);// 创建一个AnimationSet对象
/* 设置淡出效果 */
AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0);
alphaAnimation.setDuration(3000);
/* 设置旋转效果 */
RotateAnimation rotateAnimation = new RotateAnimation(0, 360,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
rotateAnimation.setDuration(3000);
/* 设置缩放效果 */
ScaleAnimation scaleAnimation = new ScaleAnimation(1, 0.0f, 1, 0.0f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
animationSet.addAnimation(scaleAnimation);
animationSet.setFillAfter(true);
animationSet.setFillBefore(false);
animationSet.setDuration(3000);
/* 给animationSet添加动画 */
animationSet.addAnimation(alphaAnimation);
animationSet.addAnimation(rotateAnimation);
animationSet.addAnimation(scaleAnimation);