mercredi 11 janvier 2017

How Do I generate animation using Random function in Android?

I am attempting to have a button flash using it's Alpha which it does to correctly however I want to set the amount of times the button flashes using the Random function and between the values of 1 and 10 times.

My Current Code -

private void sequenceFunction() {
        //Change Alpha from Fully Visible to Invisible
        final Animation animation = new AlphaAnimation(1, 0);
        //Duration - A Second
        animation.setDuration(1000);
        //Animation Rate
        animation.setInterpolator(new LinearInterpolator());
        animation.setStartOffset(250);
        animation.setDuration(250);
        //Repeat Animation 
        animation.setRepeatCount(5);
        // Reverse animation at the end so the button will fade back in
        animation.setRepeatMode(Animation.REVERSE);

        //Button 1 Flashes
        final Button btn = (Button) findViewById(R.id.button);
        btn.startAnimation(animation);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View view) {
                view.clearAnimation();
            }
        });

}

I have done some research on this subject however have come up empty handed and have used Random in previous projects but not using Animation. Has anyone got any suggestions on how I could get this working ?




Aucun commentaire:

Enregistrer un commentaire