Question

I'm having a rather odd problem with Animation in my project. In the screenshots posted below you can clearly see the Totals card leaving some sort of trail upon animation. This problem is reproducible on a stock Nexus 7 running 4.2.2. The Totals card has a Google Now style Animation. It is important to note that the container for the Totals card is a Fragment, the Menu to the left in the landscape screenshot is a different Fragment, and the bottom buttons are part of the Activity that the Fragments are attached to.

Landscape Screenshot

Portrait screenshot

I can't seem to find a solution online, I have tried setFillAfter"true" and offsetting the beginning of the animation. The trail in the Activity's buttons on the bottom ("Previous & "Next) disappears when one of the buttons are pressed.

Here's the code in the onCreateView of the Totals Fragment:

    final View view = inflater.inflate(R.layout.fragment_totals,
            container, false);      

    Fonts.setRobotoThinFont(getActivity(), view);

    final LinearLayout mContainer = (LinearLayout)
            view.findViewById(R.id.container);

    final View mCard = inflater
            .inflate(R.layout.view_simpletotal, mContainer, false);

    Animation animation = AnimationUtils.loadAnimation(getActivity(),
            R.anim.card_animation);

    mContainer.addView(mCard);

    mCard.startAnimation(animation);  

    return view;

Any help would be much appreciated!

Was it helpful?

Solution

You can easily get rid of it by simply invalidating the container activity when the animation ends.

OTHER TIPS

I suggest you to use setLayoutAnimation() method of ViewGroup class. I think it will help you.
For example, you can write this code inside your fragment class :

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ...
    rootView.setLayoutAnimation(getLayoutAnimation());
    ...
}
private LayoutAnimationController getLayoutAnimation() {
    Animation animation = new RotateAnimation(30, 0, -100, 0);
    animation.setDuration(1000);
    LayoutAnimationController layoutAnimationController = new LayoutAnimationController(animation);
    return layoutAnimationController;
}

See what will happen with animation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top