use*_*910 12 android android-animation
我正在为RelativeLayout使用右移动动画.
我试图将"可见性"设置为"GONE" onAnimationEnd(),但它不起作用.动画视图仍然存在于停止的位置.
这是我使用的代码:
从右到左创建动画:
TranslateAnimation animate = new TranslateAnimation(0,-rlImages.getWidth()/2,0,0);
animate.setDuration(1000);
animate.setFillAfter(true);
Run Code Online (Sandbox Code Playgroud)
将动画设置为布局:
centre_leftanimate.startAnimation(animate);
Run Code Online (Sandbox Code Playgroud)
添加侦听器到动画:
animate.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
centre_leftanimate.setVisibility(View.GONE); // I wants to make the visibility of view to gone,but this is not working
half_left.setVisibility(View.VISIBLE);
}
});
Run Code Online (Sandbox Code Playgroud)
如何在动画结束后使动画视图的可见性不可见?
请建议.
3c7*_*c71 20
我有同样的问题,除了我实际删除了动画视图,但动画仍然存在!
简单的解决方案是实际取消动画,然后您可以隐藏或删除视图.
animatedView.getAnimation().cancel();
Run Code Online (Sandbox Code Playgroud)
或者如果你还有你的动画对象:
animation.cancel();
Run Code Online (Sandbox Code Playgroud)
编辑:似乎有一些遗留上述解决方案,所以我添加了这个:
animatedView.setAnimation(null);
Run Code Online (Sandbox Code Playgroud)
您可以根据需要设置视图的可见性。如果在动画开始后立即将其设置为View.INVISIBLE,则动画将可见,并且一旦动画停止,View就会消失。我认为您的代码的问题可能是您使用的是 GONE 而不是 INVISIBLE。第二个问题可能是您在设置侦听器之前启动动画,但使用我的解决方案,您实际上不需要任何侦听器。另外,去掉 FillAfter 选项。
TranslateAnimation animate = new TranslateAnimation(0,-rlImages.getWidth()/2,0,0);
animate.setDuration(1000);
centre_leftanimate.startAnimation(animate);
centre_leftanimate.setVisibility(View.INVISIBLE);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19579 次 |
| 最近记录: |