Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Android, setVisibility/animation issue

  • 16-01-2013 11:36am
    #1
    Moderators, Science, Health & Environment Moderators, Social & Fun Moderators, Society & Culture Moderators Posts: 60,110 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,110 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,110 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,110 Mod ✭✭✭✭Tar.Aldarion


    Got it working with onAnimationEnd, great thanks.


  • Advertisement
Advertisement