我正在使用翻译和缩放动画。首先,我将框架布局转换为屏幕中心,然后使用布局参数将其位置参数设置为屏幕中心。这很好用!在翻译动画结束时,我运行缩放动画,我的布局缩放为原始大小的 2 倍。实际上我的框架布局(我正在制作动画)由按钮和图像视图组成。与在 android 中一样,动画不会改变视图,它只会改变必须绘制的位置。现在我的问题是我无法让我的按钮工作。因为它们实际上并不存在!
我通过在动画结束后设置其位置参数找到了平移动画的解决方案。这会将视图永久移动到新位置。
但是,在缩放动画的情况下,我必须更改布局的大小以及其中的子级。但它不起作用,因为我将原始高度宽度与比例因子相乘。这是我的缩放动画代码。
ScaleAnimation scaleAnim = new ScaleAnimation(1.0f, 2.0f, 1.0f,
2.0f, Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnim.setDuration(600);
// scaleAnim.setFillEnabled(true);
scaleAnim.setFillAfter(true);
view.setAnimation(scaleAnim);
view.startAnimation(scaleAnim);
scaleAnim.setAnimationListener(new AnimationListener() {
public void onAnimationStart(Animation animation) {
}
public void onAnimationRepeat(Animation animation) {
}
public void onAnimationEnd(Animation animation) {
FrameLayout.LayoutParams par = (FrameLayout.LayoutParams) view
.getLayoutParams();
par.height = view.getMeasuredHeight() * 2;
par.width = view.getMeasuredWidth() * 2;
view.setLayoutParams(par);
view.requestLayout();
}
});
ps setFillAfter(true) 和 setFillEnabled(true) 不是解决方案。