Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Android, setVisibility/animation issue

  • 16-01-2013 12:36PM
    #1
    Moderators, Science, Health & Environment Moderators, Social & Fun Moderators, Society & Culture Moderators Posts: 60,119 Mod ✭✭✭✭


    I have a linearLayout that disappears when I hit a button, it comes back when I press the button again. But it does it so fast, it doesn't look nice. I do this via:

    disappearView.setVisibility(View.GONE);
    I would like to add some animation... If I just set visibity to invisible the space where the layout was is still there. So I tried this:
    if (disappearView.getVisibility() == View.VISIBLE){
                Animation out = AnimationUtils.makeOutAnimation(this, true);
                disappearView.startAnimation(out);
                disappearView.setVisibility(View.INVISIBLE);
                disappearView.setVisibility(View.GONE);
    
            }
            else {
                Animation in = AnimationUtils.loadAnimation(this, android.R.anim.fade_in);
                disappearView.startAnimation(in);
                disappearView.setVisibility(View.VISIBLE);      
            }
    
    This does the animation too fast and disappears. You can't see it at all. Do I need to use a thread to start gone after invisible is set...or a delay? Or is there a better way of doing all this?


Comments

  • Registered Users, Registered Users 2 Posts: 18,272 ✭✭✭✭Atomic Pineapple


    I think you have to calculate your own animation for this. See this link:

    http://stackoverflow.com/questions/2634073/how-do-i-animate-view-setvisibilitygone


  • Moderators, Science, Health & Environment Moderators, Social & Fun Moderators, Society & Culture Moderators Posts: 60,119 Mod ✭✭✭✭Tar.Aldarion


    I was looking at that way yeah, might try it as an improvement later but the method I have above does an animation that I like fine out of the box, which is handier! When that animation is done I want to call disappearView.setVisibility(View.GONE); All i need is some way to see that the previous command is done, or implement a small delay. The way it is now, in the middle of the animation disappearView.setVisibility(View.GONE); gets called and the layout disappears too fast.


  • Registered Users, Registered Users 2 Posts: 18,272 ✭✭✭✭Atomic Pineapple


    I was looking at that way yeah, might try it as an improvement later but the method I have above does an animation that I like fine out of the box, which is handier! When that animation is done I want to call disappearView.setVisibility(View.GONE); All i need is some way to see that the previous command is done, or implement a small delay. The way it is now, in the middle of the animation disappearView.setVisibility(View.GONE); gets called and the layout disappears too fast.

    Ah OK, have you tried using an AnimationListener to detect the end of the animation? Not sure if it can be used with AnimationUtils though.

    http://developer.android.com/reference/android/view/animation/Animation.AnimationListener.html


  • Moderators, Science, Health & Environment Moderators, Social & Fun Moderators, Society & Culture Moderators Posts: 60,119 Mod ✭✭✭✭Tar.Aldarion


    Yeah thanks that's what I got suggested also but cant seem to get them working together yet. I tried making a thread to wait for a second but it just crashed the app, damn.


  • Moderators, Science, Health & Environment Moderators, Social & Fun Moderators, Society & Culture Moderators Posts: 60,119 Mod ✭✭✭✭Tar.Aldarion


    Got it working with onAnimationEnd, great thanks.


  • Advertisement
Advertisement