[英]Android, setVisibility/animation issue
I have a linearLayout
that disappears when I hit a button, it comes back when I press the button again. 当我按下按钮时,我有一个
linearLayout
消失,当我再次按下按钮时它会返回。 But it does it so fast, it doesn't look nice. 但它做得如此之快,看起来并不好看。 I do this via:
我这样做是通过:
disappearView.setVisibility(View.GONE);
I would like to add some animation... If I just set visibity to invisible the space where the layout was is still there. 我想添加一些动画......如果我只是将visibity设置为隐藏布局所在的空间仍然存在。 So I tried this:
所以我尝试了这个:
if (disappearView.getVisibility() == View.VISIBLE){
Animation out = AnimationUtils.makeOutAnimation(this, true);
disappearView.startAnimation(out);
disappearView.setVisibility(View.INVISIBLE);
disappearView.setVisibility(View.GONE);
}
else {
Animation in = AnimationUtils.loadAnimation(this, android.R.anim.fade_in);
disappearView.startAnimation(in);
disappearView.setVisibility(View.VISIBLE);
}
This does the animation too fast and disappears. 这会使动画太快而消失。 You can't see it at all.
你根本看不到它。 Do I need to use a thread to start
gone
after invisible
is set...or a delay? 设置
invisible
后,我是否需要使用线程开始gone
...或延迟? Or is there a better way of doing all this? 或者有更好的方法来做这一切吗?
I'm not sure exactly what you're trying to accomplish...do you want the LinearLayout to fade out over a little bit of time rather than instantly disappear? 我不确定你要完成的是什么......你想让LinearLayout在一点点时间内消失而不是立即消失吗? And then once it fades out be removed from the parent via View.GONE?
然后,一旦淡出,通过View.GONE从父母中移除?
If so, you can use an AlphaAnimation for the fade out and then attach a listener like EvZ posted: 如果是这样,您可以使用AlphaAnimation进行淡出,然后附加一个像EvZ发布的监听器:
AlphaAnimation fadeOutAnimation = new AlphaAnimation(1, 0); // start alpha, end alpha
fadeOutAnimation.setDuration(1000); // time for animation in milliseconds
fadeOutAnimation.setFillAfter(true); // make the transformation persist
fadeOutAnimation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationEnd(Animation animation) {
linearLayout.setVisibility(View.GONE);
}
@Override
public void onAnimationRepeat(Animation animation) { }
@Override
public void onAnimationStart(Animation animation) { }
});
linearLayout.setAnimation(fadeOutAnimation);
您可以尝试使用onAnimationEnd
: Animation.AnimationListener
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.