-1
Ich möchte eine Toss App machen .. es ist Spining alle Zeit und wird nicht aufhören, einen Kopf oder Schwanz zu zeigen .. ich will, dass wenn ich auf die Münze klicken, dann sollte es für drehen 2 3 Sekunden und stoppt dann, um Kopf oder Schwanz in zufälliger Auswahl zu zeigen ... aber es dreht sich ständig. Hier ist der Code ...Ich möchte Animation auf ImageView setzen
public class MainActivity extends AppCompatActivity {
ImageView Coin;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Coin=(ImageView) findViewById(R.id.ImgViewcoin);
Coin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Animation animation = new AlphaAnimation(1, 0);
animation.setInterpolator(new DecelerateInterpolator());
animation.setDuration(3000);
Coin.startAnimation(animation);
animation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
final int[] photos = {R.drawable.heads, R.drawable.tails};
final ImageView image = (ImageView) findViewById(R.id.ImgViewcoin);
final Random ran = new Random();
int i = ran.nextInt(photos.length);
image.setImageResource(photos[i]);
image.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
int k = ran.nextInt(photos.length);
image.setImageResource(photos[k]);
}
}
);
}
@Override
public void onAnimationEnd(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
Coin.startAnimation(animation);
}
});
}
}
Rufen Sie in der Bildansicht 'OnCickListener' –
' coin.clearanimation' auf, wenn Sie in diesem Rückruf eine Animation erhalten. –