android 左移动画_Android的动画,移动和旋转的同时

I am working on animating an image view and that moves to the right and rotates at the same time. I can get the item to move using

animation = new TranslateAnimation(0, level, 0, 0);

animation.setDuration(1000);

animation.setRepeatCount(0);

animation.setFillAfter(true);

Level is the variable I have defined at the time. I know the code for rotate is

RotateAnimation rotate = new RotateAnimation(0,rotate,0,0);

rotate.setDuration(1000);

rotate.setRepeatCount(0);

animation.setFillAfter(true);

bPick.setAnimation(rotate);

Again rotate is variable I have defined at the top.

My question is, how do I combine these two? I have tried using a thread

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);

}

};

};

That will have it move to the right fine, however if I try adding in rotation as well, it doesnt work, or it will crash.

Any help would be much appreciated, cheers

EDIT

The reason I require this is that I have a gauge with a pick.

I require the gauge pick to move to the right while slowly rotating to the right. How much it moves to the right is based on a int variable set up. It will go from 0 - 100. 0 being the start position and 100, it will be moved to the right and look like this

解决方案

You need to use an AnimationSet.

An example in XML I made which moves an image from left to right, up and down and rotates, all at the same time.

android:pivotX="50%" android:pivotY="50%" android:repeatCount="4"

android:repeatMode="reverse" android:duration="2000"

android:interpolator="@android:anim/linear_interpolator" />

android:fromYDelta="100%p" android:toYDelta="0" android:duration="10000"

android:interpolator="@android:anim/linear_interpolator" />

android:fromYDelta="30" android:toYDelta="-30" android:repeatMode="reverse"

android:repeatCount="4" android:interpolator="@android:anim/linear_interpolator"

android:duration="2000" />

Code example (not to replicate above):

AnimationSet animationSet = new AnimationSet(true);

TranslateAnimation a = new TranslateAnimation(

Animation.ABSOLUTE,200, Animation.ABSOLUTE,200,

Animation.ABSOLUTE,200, Animation.ABSOLUTE,200);

a.setDuration(1000);

RotateAnimation r = new RotateAnimation(0f, -90f,200,200);

r.setStartOffset(1000);

r.setDuration(1000);

animationSet.addAnimation(a);

animationSet.addAnimation(r);

(Taken from here)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值