Can LayoutAnimationController animate only specified Views

血红的双手。 提交于 2019-11-29 05:15:06

I wasn't able to find a way to change Android's LayoutAnimationController, but did come up with a simple solution that does what I want. I created a View subclass that can selectively ignore calls to run an animation if I so choose.

public class AnimationAverseView extends View {

    private boolean mIsAnimatable = true;

    public void setAnimatible(boolean isAnimatable) {
        if (!isAnimatable) {
            clearAnimation();
        }
        mIsAnimatable = isAnimatable;
    }

    @Override
    public void startAnimation(Animation animation) {
        if (mIsAnimatable) {
            super.startAnimation(animation);
        }
    }
}

I did not worry about any other possible animation-related methods, since I only animate the Views via a LayoutAnimationController.

geoff.weatherall

I cannot add a comment to the accepted answer, so adding some additional information here. The comment from happydude (Feb 17) was correct for me as well. I had a FrameLayout as the outermost View for my ListView header, and I needed to override the setAnimation() method to prevent the header from being animated with the rest of the list. So you should check out which other animation methods you might need to override.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!