我想将连续的动画(例如 ScaleAnimation)应用到显示资源图像的 ImageView。动画由按钮触发。例如,我想在每次单击按钮时逐渐放大图像。
我已在动画上设置 fillAfter="true"。但是,所有动画都是从 ImageView 的原始状态开始的。看起来好像 ImageView 重置了它的状态并且动画始终是相同的,而不是从上一个动画的最终状态开始。
我做错了什么?
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button)findViewById(R.id.Button01);
button.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
animate();
}});
}
private void animate() {
ImageView imageView = (ImageView) findViewById(R.id.ImageView01);
ScaleAnimation scale = new ScaleAnimation((float)1.0, (float)1.5, (float)1.0, (float)1.5);
scale.setFillAfter(true);
scale.setDuration(500);
imageView.startAnimation(scale);
}
最佳答案
It seems as if the ImageView resets its state and the animation is always the same, instead of starting from the final state of the previous animation.
没错!我确信 fillAfter="true"
有用途,但我还没有弄清楚它的意义。
您需要做的是在每个相关的Animation
上设置一个AnimationListener
,并在监听器的onAnimationEnd()
中执行一些操作实际上保留动画的最终状态。我还没有玩过 ScaleAnimation,所以我不太确定“保持最终状态”的方法是什么。如果这是一个 AlphaAnimation
,从 1.0
到 0.0
,您将使小部件 INVISIBLE
或 例如,
。onAnimationEnd()
中的 GONE
关于android - 在Android中对ImageView应用连续的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2563941/