Mikhail
Mikhail

Reputation: 608

Android ScrollView loses clip on rotation animation

I'm using Rotate3dAnimation to flip a card view which contains a ScrollView. But during animation ScrollView loses a clip somehow so I see top and bottom of ScrollView content outside the card view (and ScrollView) bounds until animation is done.

Why is that and how to beat this behaviour?

Upvotes: 2

Views: 241

Answers (1)

Peter Ball
Peter Ball

Reputation: 61

This unfortunately happens due to the way the bounds for the ScrollView are calculated. It seems the bounds are not "rotated" along with the view.

One work around is to take a snapshot of each view - both the front and the back of the card - and then to animate between these snapshots above the actual views.

The code would look something like this:

firstView.setDrawingCacheEnabled(true);
firstAnimationView.setBackgroundDrawable(new BitmapDrawable(firstView.getDrawingCache()));

secondView.setDrawingCacheEnabled(true);
secondAnimationView.setBackgroundDrawable(new BitmapDrawable(secondView.getDrawingCache()));

Animation flipOutAnimation = createFlipOutAnimation();

flipOutAnimation.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationEnd(Animation animation) {
            firstAnimationView.setVisibility(View.GONE);
        }

        ...

    });

Animation flipInAnimation = createFlipInAnimation();

flipInAnimation.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationEnd(Animation animation) {

            animationBackgroundView.setVisibility(View.GONE);
            secondAnimationView.setVisibility(View.GONE);
        }

        ...

    });

firstAnimationView.startAnimation(flipOutAnimation);
secondAnimationView.startAnimation(flipInAnimation);

animationBackgroundView.setVisibility(View.VISIBLE);
firstAnimationView.setVisibility(View.VISIBLE);
secondAnimationView.setVisibility(View.VISIBLE);

For backwards compatible flip animations, I use http://genzeb.github.io/flip/

Upvotes: 2

Related Questions