Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Alpha animation not starting

In my menu I'm trying to implement a button that, when click, makes another button appear using an alpha animation.

    final Animation animAlphaUp = new AlphaAnimation(0.0f, 1.0f);
    animAlphaUp.setDuration(200);

    ImageButton start_button = (ImageButton) findViewById(R.id.start_button);
    ImageButton options_button = (ImageButton) findViewById(R.id.options_button);
    final ImageButton mute_button = (ImageButton) findViewById(R.id.options_button);

    options_button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mute_button.startAnimation(animAlphaUp);
        }
    });

    mute_button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {   
        }
    });

but when the options button is clicked nothing happens. The animation works, i know this because if i write this:

options_button.setOnClickListener(new View.OnClickListener() {      
    @Override
    public void onClick(View v) {
       options_button.startAnimation(animAlphaUp);
    }
});

the animation works on the button that is clicked.

What am i doing wrong?

Thanks.

like image 527
CalvinWylie Avatar asked Sep 04 '26 04:09

CalvinWylie


1 Answers

Try using your_button_name.startAnimation(your_animation_name); instead.

Worked for me.

like image 174
aDeveloper Avatar answered Sep 06 '26 20:09

aDeveloper



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!