Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
313 views
in Technique[技术] by (71.8m points)

android - Can LayoutAnimationController animate only specified Views

Is it possible to override Android's LayoutAnimationController in such a way that only certain child Views that I specify inside a ViewGroup will animate? My goal is to choose an arbitrary set of the child views based on the current state of the Activity and animate them with the same animation at exactly the same time, then at a later time choose a different arbitrary set of child views and do the same thing. I would like to be able to do this continually until the Activity is finished running.

So far I have looked at and dismissed a couple of options:

  1. Calling startAnimation(Animation) the specific child views individually, however there is not a guarantee that they will all start and end at exactly the same time, especially if the number of views in the arbitrary set is large.
  2. Overriding LayoutAnimationController.getAnimationForView() seemed like it would be the easiest way, but the method is final and cannot be overridden.

I have been scratching my head for some time on this and figured I would give Stack Overflow a shot.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...