【发布时间】:2019-07-08 09:04:04
【问题描述】:
我正在创建一个应用程序,从资源中加载可绘制对象并将其显示在占位符 ImageView 中。 当用户单击按钮加载下一张图片时,我创建了一个动画,将旧图片移动并缩放到新位置,并将新的可绘制对象加载到占位符。
在 30 张图像之后,我正在运行 OOM,这是有道理的。
我要做的是在动画结束后重新采样每个图像,因为我从 500X500 占位符开始并以 1/3 结束。
问题是在我完成动画后,ImageView 的宽度和高度保持不变。 缩放动画不应该改变ImageView的宽高吗?
这是动画的代码:
//create the animation
imageView.setPivotX(0);
imageView.setPivotY(0);
imageView.animate()
.scaleX(scaleX) //about 0.3
.scaleY(scaleY) //about 0.3
.x(finalX) //location x of the image
.y(finalY) //location y of the image
.setListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
int reqWidth = imageView.getWidth(); //result 500 as expected
int reqHeight = imageView.getHeight();//result 500 as expected
Drawable image = imageView.getDrawable();
}
@Override
public void onAnimationEnd(Animator animation) {
int reqWidth = imageView.getWidth();//result 500 - why?
int reqHeight = imageView.getHeight();//result 500 - why?
Drawable image = imageView.getDrawable();
}
@Override
public void onAnimationCancel(Animator animation) {}
@Override
public void onAnimationRepeat(Animator animation) {}
});
【问题讨论】:
-
这是动画的完整代码吗?
-
是的 - 在那之后我什么都不做
标签: android android-animation scale