使用步骤:
1.在res/anim/
下定义动画文件,例如取名为translate.xml。
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fillAfter="true"
android:fromXDelta="50"
android:fromYDelta="50"
android:toXDelta="500"
android:toYDelta="300">
</translate>
有一点需要注意,fromXDelta
和fromYDelta
都是相对于要执行动画view的左上角为原点,所以一般取0就行。
2.使用AnimationUtils
加载动画文件
Animation animation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.translate);
3.通过View的startAnimation方法传入Animation对象并启动动画。
ImageView imageView=findViewById(R.id.imageView);
imageView.startAnimation(animation);
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有