keltkelt Asked:2020-04-06 01:52:04 +0000 UTC2020-04-06 01:52:04 +0000 UTC 2020-04-06 01:52:04 +0000 UTC 为什么动画没有结束? 772 第一个视图飞到第二个视图并消失。但后来它没有出现。似乎在动画结束后 - 一切都应该到位。 view.animate() .x(view2.getX()) .y(view2.getY()) .alpha(0.0f) .scaleX(0.0f) .setDuration(500) .start(); android 1 个回答 Voted Best Answer Shwarz Andrei 2020-04-06T03:50:30Z2020-04-06T03:50:30Z 在您的情况下,动画可能会有所不同,它是 ViewPropertyAnimator,请更改视图参数。因此,在您的情况下动画完成后,视图将具有getAlpha = 0f getX = 0f. ViewAnimation 最有可能适合您,它不会转换价值。并且结束后,视图将使用原始数据进行绘制。 <set android:shareInterpolator="false"> <scale android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:fromXScale="1.0" android:toXScale="1.4" android:fromYScale="1.0" android:toYScale="0.6" android:pivotX="50%" android:pivotY="50%" android:fillAfter="false" android:duration="700" /> <set android:interpolator="@android:anim/decelerate_interpolator"> <scale android:fromXScale="1.4" android:toXScale="0.0" android:fromYScale="0.6" android:toYScale="0.0" android:pivotX="50%" android:pivotY="50%" android:startOffset="700" android:duration="400" android:fillBefore="false" /> <rotate android:fromDegrees="0" android:toDegrees="-45" android:toYScale="0.0" android:pivotX="50%" android:pivotY="50%" android:startOffset="700" android:duration="400" /> </set> </set> ImageView spaceshipImage = (ImageView) findViewById(R.id.spaceshipImage); Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(this, R.anim.hyperspace_jump); spaceshipImage.startAnimation(hyperspaceJumpAnimation); PS对于无限动画有一个repeatCount参数 android:repeatCount="infinite",我可能会犯错,如果有什么纠正它。 例子: 与您的问题类比,除了翻译,但我认为您会通过一个工作示例快速弄清楚。 @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.menu_activity); ImageView ivCoin = findViewById(R.id.iv_coin); ivCoin.setOnClickListener(v -> v.startAnimation(getCoinAnimSet())); } private AnimationSet getCoinAnimSet(){ AnimationSet animationSet = new AnimationSet(true); AlphaAnimation alphaAnimation = new AlphaAnimation(1f, 0f); alphaAnimation.setDuration(500); alphaAnimation.setRepeatCount(Animation.INFINITE); alphaAnimation.setRepeatMode(Animation.REVERSE); ScaleAnimation scaleAnimation = new ScaleAnimation(1f, 0f, 1f, 1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); scaleAnimation.setDuration(500); scaleAnimation.setRepeatCount(Animation.INFINITE); scaleAnimation.setRepeatMode(Animation.REVERSE); animationSet.addAnimation(alphaAnimation); animationSet.addAnimation(scaleAnimation); return animationSet; } 硬币旋转动画
在您的情况下,动画可能会有所不同,它是 ViewPropertyAnimator,请更改视图参数。因此,在您的情况下动画完成后,视图将具有
getAlpha = 0f getX = 0f.ViewAnimation 最有可能适合您,它不会转换价值。并且结束后,视图将使用原始数据进行绘制。
PS对于无限动画有一个repeatCount参数
android:repeatCount="infinite",我可能会犯错,如果有什么纠正它。与您的问题类比,除了翻译,但我认为您会通过一个工作示例快速弄清楚。
硬币旋转动画