1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| coin = (ImageView) findViewById(R.id.coin);
coin.setImageResource(R.drawable.heads);
btn = (Button) findViewById(R.id.btn);
r = new Random();
btn.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
tourner_coin2();
}
});
}
private void tourner_coin2()
{
//
coin.setImageResource(RANDOM.nextFloat() > 0.5f ? R.drawable.heads : R.drawable.tails);
RotateAnimation rotate = new RotateAnimation(360 * 12,0,
RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f);
rotate.setDuration(2000);
coin.startAnimation(rotate); |
Partager