2013-05-16 10 views
3

Как переместить объект в пути во время его вращения вокруг своей оси, как на следующем рисунке:Как перемещать объект по пути, вращая его вокруг своей оси?

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 

ответ

5

Хорошо изменяющий порядок перевода и Rotate Animations Исправлена ​​проблема.

Смежные вопросы