Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,739,676 Members 51,434 Now Online
XDA Developers Android and Mobile Development Forum

Animations not working

Tip us?
 
Chromium
Old
(Last edited by Chromium; 13th March 2014 at 05:24 PM.)
#1  
Chromium's Avatar
Recognized Contributor - OP
Thanks Meter 5672
Posts: 4,358
Join Date: Oct 2012
Location: Toronto

 
DONATE TO ME
Default Animations not working

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:
Select 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:
Select 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:
Select 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.
 
GRYMALA
Old
#2  
Junior Member
Thanks Meter 6
Posts: 19
Join Date: May 2014
Try this:

Code:
Select 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.setAlpha(0);
            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.INVISIBLE);
                }
                
            });
            textView1.startAnimation(fadeOut);
        }
    }
});
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes