这是一个转盘转动的效果
//线程启动后开始进行刮奖操作
private void startRun() {
thread = new Thread(new Runnable() {@Override
public void run() {
try {
set_destdegree(i);
Message msg = new Message();
msg.what = 1;
hand.sendMessage(msg);
Thread.sleep(1000);
Message msg1 = new Message();
msg1.what = 2;
hand.sendMessage(msg1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
thread.start();
}
private RotateAnimation ani;
int i;//中奖结果
public void handleMessage(android.os.Message msg) {
//开始动画旋转
//table是转盘,point是指针
ani = new RotateAnimation(0f, destdegree,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
ani.setFillAfter(true);
ani.setDuration(800);
table.startAnimation(ani);
point.setClickable(false);
} else if (msg.what == 2) {
//显示结果
Toast.LENGTH_LONG).show();
// 如果允许再转一次,就设置clickable为true
point.setClickable(true);
}
};
};
//计算旋转角度
public int set_destdegree(int i,int n) {
int destdegree = 360/n * i + 360 * 3;
return destdegree;
}