我正在制作一个动画效果,使得一个图片视图在向右移动的同时进行旋转。我可以使用以下代码实现物品的移动:
animation = new TranslateAnimation(0, level, 0, 0);
animation.setDuration(1000);
animation.setRepeatCount(0);
animation.setFillAfter(true);
Level 是我在定义时使用的变量。我知道旋转的代码是:
RotateAnimation rotate = new RotateAnimation(0,rotate,0,0);
rotate.setDuration(1000);
rotate.setRepeatCount(0);
animation.setFillAfter(true);
bPick.setAnimation(rotate);
再次提醒一下,rotate是我在顶部定义的变量。
我的问题是,如何将这两者结合起来?我已经尝试使用线程
private Runnable myThread = new Runnable() {
@Override
public void run() {
while (level < 100) {
try {
myHandle.sendMessage(myHandle.obtainMessage());
Thread.sleep(15);
} catch (Throwable t) {
}
}
}
Handler myHandle = new Handler() {
@Override
public void handleMessage(Message msg) {
level++;
animation = new TranslateAnimation(0, level, 0, 0);
animation.setDuration(1000);
animation.setRepeatCount(0);
animation.setFillAfter(true);
bPick.setAnimation(animation);
}
};
};
那样可以使它向右移动,但是如果我尝试添加旋转,它就无法工作,或者会崩溃。
任何帮助将不胜感激,谢谢!
编辑
我需要这样做的原因是我有一个带拨片的仪表。
我需要仪表挑选器向右移动并缓慢向右旋转。其向右移动的距离基于设置的int变量。它将从0-100。 0是起始位置,100时,它将向右移动,并像这样显示:
RotateAnimation
在构造函数中采用了pivot等参数。 - Ricky