写一个android studio 付款成功跳转的动画
时间: 2023-10-05 08:08:29 浏览: 49
首先,在XML布局文件中定义一个ImageView:
```
<ImageView
android:id="@+id/iv_animation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_check_circle"
android:visibility="invisible"
android:layout_gravity="center"/>
```
然后,在Java代码中实现动画效果:
```
// 获取ImageView
ImageView ivAnimation = findViewById(R.id.iv_animation);
// 定义动画
AnimationSet animationSet = new AnimationSet(true);
ScaleAnimation scaleAnimation = new ScaleAnimation(1f, 3f, 1f, 3f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
AlphaAnimation alphaAnimation = new AlphaAnimation(1f, 0f);
animationSet.addAnimation(scaleAnimation);
animationSet.addAnimation(alphaAnimation);
animationSet.setDuration(1000);
// 设置动画监听器
animationSet.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// 动画开始时,显示ImageView
ivAnimation.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationEnd(Animation animation) {
// 动画结束时,隐藏ImageView,并跳转到下一页
ivAnimation.setVisibility(View.INVISIBLE);
Intent intent = new Intent(MainActivity.this, SuccessActivity.class);
startActivity(intent);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
// 开始动画
ivAnimation.startAnimation(animationSet);
```
这个动画效果,是一个放大并逐渐消失的圆圈。通过设置动画监听器,在动画结束时跳转到下一页。具体的实现方式,可以根据自己的需求进行调整。