Android 图片翻转动画

font.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" 
     android:interpolator="@android:anim/accelerate_interpolator"> 
     <scale 
        android:fromXScale="0.0" 
        android:toXScale="1.0" 
        android:fromYScale="1.0" 
        android:toYScale="1.0" 
        android:pivotX="50%" 
        android:pivotY="50%" 
        android:duration="150"/> 
</set>

back.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" 
     android:interpolator="@android:anim/accelerate_interpolator"> 
     <scale 
        android:fromXScale="1.0" 
        android:toXScale="0.0" 
        android:fromYScale="1.0" 
        android:toYScale="1.0" 
        android:pivotX="50%" 
        android:pivotY="50%" 
        android:duration="150"/> 
</set>

使用:

				Animation aniback = AnimationUtils.loadAnimation(getContext(), R.anim.back);
				aniback.setAnimationListener(new AnimationListener()
				{
					@Override
					public void onAnimationStart(Animation animation)
					{
					}

					@Override
					public void onAnimationRepeat(Animation animation)
					{
					}

					@Override
					public void onAnimationEnd(Animation animation)
					{
						if (isCNPic)
						{
							ivPic.setImageResource(R.drawable.system_tip1);
							isCNPic = false;
						}
						else
						{
							ivPic.setImageResource(R.drawable.system_tip0);
							isCNPic = true;
						}
						ivPic.startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.font));
					}
				});
				ivPic.startAnimation(aniback);


  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
你可以使用Android中的属性动画(Property Animation)来实现图片旋转动画。具体实现步骤如下: 1.在res/anim文件夹下创建rotate.xml文件,内容如下: ```xml <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="0" android:toDegrees="360" android:pivotX="50%" android:pivotY="50%" android:repeatCount="0" android:duration="1000" /> ``` 其中,fromDegrees和toDegrees分别表示旋转的起点角度和终点角度;pivotX和pivotY表示旋转中心点的位置;repeatCount表示动画重复次数,这里设置为0表示不重复;duration表示动画的持续时间,这里设置为1000毫秒。 2.在代码中找到要进行旋转动画的ImageView控件,使用如下代码进行动画设置: ```java ImageView imageView = findViewById(R.id.image_view); ObjectAnimator rotationAnimator = ObjectAnimator.ofFloat(imageView, "rotation", 0, 360); rotationAnimator.setDuration(1000); rotationAnimator.setRepeatCount(ValueAnimator.INFINITE); rotationAnimator.setInterpolator(new LinearInterpolator()); rotationAnimator.start(); ``` 其中,R.id.image_view表示ImageView控件的ID;ObjectAnimator是属性动画中的旋转动画,ofFloat方法中的第一个参数表示要进行动画的控件,第二个参数表示动画类型(这里是旋转),第三个参数表示旋转起始角度,第四个参数表示旋转终止角度;setDuration方法表示动画持续时间;setRepeatCount方法设置动画重复次数,这里设置为无限循环;setInterpolator方法设置动画插值器,这里设置为线性插值器;start方法开始动画。 这样就可以实现图片旋转动画了。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值