简体   繁体   English

Android Alpha动画不会在动画过程中重新绘制

[英]Android alpha animation not repainting during the animation

I have an activity with a slidingdrawer that comes up as a menu. 我有一个带有滑动菜单的活动,它作为菜单出现。 when the activity starts the button is there and fades out to allow a full screen view. 活动开始时,按钮在那里并淡出以允许全屏显示。 when the button on top of the drawer is clicked (it has alpha of 0 at this point) it should fade back in and the menu popup. 单击抽屉顶部的按钮时(此时Alpha为0),它应淡入并弹出菜单。 when clicked again the menu collapses and the button fades back out. 再次单击该菜单将折叠,该按钮将逐渐淡出。 to do this I have the following code in the activity. 为此,我在活动中具有以下代码。

The initial fadeout works as expected. 初始淡出效果如预期的那样。 The activity is created and the button fades out. 活动已创建,按钮淡出。 when I click the button to expand the menu the button does not appear and when I click it again the button is there and does not fade out. 当我单击该按钮以展开菜单时,该按钮不出现,而当我再次单击它时,该按钮在那里并且不会淡出。 The odd thing is that the animation is in fact called and if I move the scrolviews behind the drawer while the animation after the animatin is called the animation does go on normally as long as I keep the views in its background moving. 奇怪的是,实际上是调用了动画,并且如果我将scrollviews移动到抽屉后面,而在调用animatin之后的动画,则只要我保持其背景中的视图运动,动画就可以正常进行。 If I stop moving those views the animation will freeze at some alpha value. 如果我停止移动这些视图,动画将冻结为某些alpha值。

Why does the first function normally while the others do not? 为什么第一个功能正常,而其他功能不正常? How do I fix this? 我该如何解决?

drawer = (SlidingDrawer) this.findViewById(R.id.slidingDrawer1);
    drawer.setOnDrawerCloseListener(new OnDrawerCloseListener(){

        public void onDrawerClosed() {
            doFadeOut();
        }       
    });
    drawer.setOnDrawerOpenListener(new OnDrawerOpenListener(){

        public void onDrawerOpened() {
            doFadeIn();             
        }           
    });


fadeOut = AnimationUtils.loadAnimation(this, R.anim.buttonfadeout);
    fadeOut.setFillAfter(true);
    fadeIn = AnimationUtils.loadAnimation(this, R.anim.buttonfadein);
    fadeIn.setFillAfter(true);
    doFadeOut(); //this is the end of onCreate and fades when the activity is created

and these are methods in the activity 这些是活动中的方法

public void doFadeOut(){
    fadeOut.reset();
    menuButton.clearAnimation();
    menuButton.startAnimation(fadeOut);
}

public void doFadeIn(){
    fadeIn.reset();
    menuButton.clearAnimation();
    menuButton.startAnimation(fadeIn);
}

Have you implemented AnimationListener ? 您实现了AnimationListener吗?

You can use onAnimationEnd() . 您可以使用onAnimationEnd() There you can put another listener which will trigger another alpha animation, for your button to fade back when you close the drawer. 您可以在此处放置另一个侦听器,该侦听器将触发另一个Alpha动画,以便您在关闭抽屉时淡出按钮。

I learned from my work with animations, that if you have more than one animation, you should always implement AnimationListener, because android cannot decide what to do with many of them on it's own. 我从动画的工作中学到,如果您有多个动画,则应该始终实现AnimationListener,因为android无法自行决定如何处理许多动画。

Check out this documentation on Android Developers: 在Android Developers上查看以下文档:

Animation Listener Documentation 动画侦听器文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM