Animate visibility modes, GONE and VISIBLE

后端 未结 8 2253
我寻月下人不归
我寻月下人不归 2021-01-30 01:54

So im trying to animate when i set the visibility of a linearlayout with other widgets, from GONE to VISIBLE and the opposite.Im using togglebuttons to show and hide. Here\'s an

8条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-30 02:24

    Visibility change itself can be easy animated by overriding setVisibility method. Look at complete code:

    public class SimpleViewAnimator extends FrameLayout
    {
        private Animation inAnimation;
        private Animation outAnimation;
    
        public SimpleViewAnimator(Context context)
        {
            super(context);
        }
    
        public void setInAnimation(Animation inAnimation)
        {
            this.inAnimation = inAnimation;
        }
    
        public void setOutAnimation(Animation outAnimation)
        {
            this.outAnimation = outAnimation;
        }
    
        @Override
        public void setVisibility(int visibility)
        {
            if (getVisibility() != visibility)
            {
                if (visibility == VISIBLE)
                {
                    if (inAnimation != null) startAnimation(inAnimation);
                }
                else if ((visibility == INVISIBLE) || (visibility == GONE))
                {
                    if (outAnimation != null) startAnimation(outAnimation);
                }
            }
    
            super.setVisibility(visibility);
        }
    }
    

提交回复
热议问题