Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Thread Deleted

Animations not working

OP Chromium

Prev Previous Post   Next Post Next
11th March 2014, 07:17 AM   |  #1  
Chromium's Avatar
OP Recognized Contributor
Flag Toronto
Thanks Meter: 6,168
 
4,400 posts
Join Date:Joined: Oct 2012
Donate to Me
More
Ive got a checkbox which should set a textview visible while checked, and hide it when its not checked. I have also created two basic animations that should appear during hiding and showing of the textview (fadeIn and fadeOut). Heres my onclicklistener for the checkbox:

Code:
checkBox1.setOnClickListener(new OnClickListener() {
    
    @Override
    public void onClick(View v) {
        fadeIn = AnimationUtils.loadAnimation(getActivity(), R.anim.fade_in);
        fadeOut = AnimationUtils.loadAnimation(getActivity(), R.anim.fade_out);
        
        if (((CheckBox) v).isChecked()) {
            
            fadeIn.setAnimationListener(new AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {
                }
                @Override
                public void onAnimationRepeat(Animation animation) {
                }
                
                @Override
                public void onAnimationEnd(Animation animation) {
                    textView1.setVisibility(View.VISIBLE);
                }
                
            });
            textView1.startAnimation(fadeIn);
            
        }
        else {
            
            fadeOut.setAnimationListener(new AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {
                }
                
                @Override
                public void onAnimationRepeat(Animation animation) {
                }
                
                @Override
                public void onAnimationEnd(Animation animation) {
                    textView1.setVisibility(View.GONE);
                }
                
            });
            textView1.startAnimation(fadeOut);
        }
    }
});
And here are my two animations:

Code:
<!-- fade_in.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="300"
    android:fillAfter="true"
    android:fromAlpha="0.0"
    android:toAlpha="1.0" />
Code:
<!-- fade_out.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="300"
    android:fillAfter="true"
    android:fromAlpha="1.0"
    android:toAlpha="0.0" />
My problem is that the fade animation only shows when I uncheck the checkbox (hide the textbox). When I try to check the box (show the textview) it just appears without showing the animation. Any help would be appreciated. Thanks in advance.

Edit: Had to move "textView1.setVisibility(View.VISIBLE);" into the onAnimationStart method.
Last edited by Chromium; 13th March 2014 at 06:24 PM.
Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes