Android动画留下文物

时间:2013-05-11 21:29:41

标签: android animation android-fragments visual-artifacts

我的项目中有一个奇怪的动画问题。在下面发布的屏幕截图中,您可以清楚地看到Totals卡在动画上留下某种痕迹。此问题可在运行4.2.2的库存Nexus 7上重现。 Totals卡有一个Google Now风格的动画。重要的是要注意Totals卡的容器是片段,横向屏幕截图中左侧的菜单是不同的片段,底部按钮是片段附加到的活动的一部分。

Landscape Screenshot

Portrait screenshot

我似乎无法在网上找到解决方案,我已经尝试过setFillAfter“true”并抵消了动画的开头。当按下其中一个按钮时,底部活动按钮(“上一个”和“下一个”)中的轨迹将消失。

以下是Totals Fragment的onCreateView中的代码:

    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;

非常感谢任何帮助!

2 个答案:

答案 0 :(得分:4)

您可以通过在动画结束时使容器活动无效来轻松摆脱它。

答案 1 :(得分:3)

我建议您使用setLayoutAnimation()类的ViewGroup方法。我认为它会对你有所帮助 例如,您可以在片段类中编写此代码:

@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;
}

了解动画会发生什么。