android - 如何在绕自身轴旋转的同时沿路径移动对象?

标签 android android-animation

如何在路径中移动对象同时绕其自身的轴旋转,如下图所示:

enter image description here

虽然这是我实际得到的:

enter image description here

这是我的代码:

AnimationSet as1 = new AnimationSet(true);
as1.setFillAfter(true);

float dist = 0.5f;
// The following is too slow just to inspect the animation
int duration = 5000; // 5 seconds
// Tried the following: RELATIVE_TO_SELF and RELATIVE_TO_PARENT but no difference
int ttype = Animation.RELATIVE_TO_SELF; // Type of translation
// Move to X: distance , Y: distance
TranslateAnimation ta1 = new TranslateAnimation( ttype,0,ttype,dist,ttype,0, ttype,dist); 
ta1.setDuration(duration);
// Add Translation to the set
as1.addAnimation(ta1);

// Rotate around its center
int rtype = Animation.RELATIVE_TO_SELF;
float rotation = 90;
RotateAnimation ra1 = new RotateAnimation(0, rotation,rtype,0.5f , rtype,0.5f );
ra1.setDuration(duration);
as1.addAnimation(ra1);

Object1.startAnimation(as1); // in my app Object1 is an ImageButton

最佳答案

很好地改变了平移和旋转动画的顺序解决了这个问题。

关于android - 如何在绕自身轴旋转的同时沿路径移动对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16580271/

相关文章:

android - RotationAsync 与 ListView 中的每一行

php - 使用PHP/Python验证ECDSA签名

java - 如何在 Firebase Android 中获取所有 Activity 的实时监听器

android - 从 RecyclerView Adapter 而不是 Activity 调用过渡动画

android - 如何将帧动画添加到包含按钮状态更改处理的 ImageButton?

java - Android:动画自定义 View

android - 滚动时处理 recyclerview 项目的文件上传进度?

android - 同一 Android 应用程序的两个实例之间的安全通信

android - 是否可以使用 ViewPager 制作此 Android 屏幕动画?

Android第一次动画不流畅