Android 动画标签——set

本文详细介绍了一个包含缩放、旋转和平移动画的XML动画合集,适用于Android应用开发中视图的动态展示。通过XML文件定义动画参数,如时长、重复次数及起始和结束状态,并提供了使用Java代码实现相同动画效果的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

作用:动画合集

文件目录:res/anim/my_set.xml

<?xml version="1.0" encoding="utf-8"?>
<scale
    android:duration="2000"
    android:fromXScale="0.0"
    android:fromYScale="0.0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:repeatCount="5"
    android:toXScale="1.4"
    android:toYScale="1.4" />

<rotate
    android:duration="1000"
    android:fromDegrees="0"
    android:interpolator="@android:anim/linear_interpolator"
    android:pivotX="50%"
    android:pivotY="50%"
    android:repeatCount="infinite"
    android:toDegrees="360" />

<translate
    android:fromXDelta="0"
    android:toXDelta="-80"
    android:fromYDelta="0"
    android:toYDelta="-80"
    android:duration="2000"
    android:fillBefore="true"/>

Java代码:
AnimationSet set = (AnimationSet ) AnimationUtils.loadAnimation(this,R.anim.my_set);
imageView.startAnimation(set);

纯代码使用:(AnimationSet)
RotateAnimation rotateAnimation = new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setFillAfter(true);// 设置保持动画最后的状态  
rotateAnimation.setDuration(3000);// 设置动画时间  
rotateAnimation.setRepeatCount(-1);//设置重复次数
imageView.startAnimation(rotateAnimation);

TranslateAnimation translateAnimation = new TranslateAnimation(0, 0, 0, 800);
translateAnimation.setRepeatCount(-1);//设置重复次数
imageView.startAnimation(translateAnimation);

AnimationSet animationSet = new AnimationSet(true);
animationSet.addAnimation(rotateAnimation);
animationSet.addAnimation(translateAnimation);
imageView.startAnimation(animationSet);

也可以单个写,方法设置都一样。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值