自定义抽签器四
让指针动起来
加上动画
//拿到控件
pointer = (Pointer) findViewById(R.id.pointer);
//如果一共5个区域,计算每个角度
angle = 360 / 5;
public void start(View view) {
//5个angle是一圈,最起码来个5圈
double random = Math.random();
double v = random * 5 + 1;
float rotateAngle = 360f * 5 + angle * (float) v;
//创建旋转动画
animation = new RotateAnimation(0, rotateAngle, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
//持续5秒,结束后保持状态
animation.setDuration(5000);
animation.setFillAfter(true);
pointer.startAnimation(animation);
}