我有一个简短的问题。
我正在尝试为 subview 设置动画以使其消失。这部分很简单,但是,在动画期间,父 View 不会调整大小。如何使父 View 在动画期间自动调整大小?
这是我当前的代码:
AnimationSet set = new AnimationSet(true);
Animation fade = new ScaleAnimation(1.f, 1.f, 1.f, 0);
Animation fade2 = new AlphaAnimation(1, 0);
set.addAnimation(fade);
set.addAnimation(fade2);
set.setDuration(2000);
set.setFillAfter(true);
bgColor.startAnimation(set);
bgColor 是我要消失的 View 。这是最终结果: Result
可以看到动画后的空隙。
有什么想法吗?
提前致谢!
最佳答案
您可以添加一个 AnimationListener 并在动画完成后更改布局
animation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationEnd(Animation animation) {
bgColor.setVisibility(View.GONE);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationStart(Animation animation) {
}
});
此外,请务必将有关 onFillAfter() 的内容放在一起!
关于android - 如何为 subview 设置动画并让父 View 自动调整大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3361348/