动画有时导致混蛋并导致滞后

时间:2014-01-16 10:33:08

标签: android animation delay

下面的代码有时引起一些混蛋和滞后,我不知道它有什么问题。

代码块是为了在屏幕内随机制作动画

@Override
public void onAnimationEnd(Animator animation) {
    super.onAnimationEnd(animation);

    int nextX = random.nextInt(width);
    int nextY = random.nextInt(height);

    animation1 = null;
    animation2 = null;

    animation1 = ObjectAnimator.ofFloat(currentView, "x", previousX,
            nextX);
    animation1.setDuration(ANIMATION_TIMING);
    animation2 = ObjectAnimator.ofFloat(currentView, "y", previousY,
            nextY);
    animation2.setDuration(ANIMATION_TIMING);
    set.playTogether(animation1, animation2);
    set.setStartDelay(250);
    set.start();

    previousX = nextX;
    previousY = nextY;
}

logcat的

01-16 17:18:12.237: D/dalvikvm(18091): GC_CONCURRENT freed 1451K, 15% free 9621K/11207K, paused 2ms+2ms
01-16 17:18:27.209: D/dalvikvm(18091): GC_CONCURRENT freed 1825K, 18% free 9639K/11655K, paused 1ms+3ms
01-16 17:18:41.926: D/dalvikvm(18091): GC_CONCURRENT freed 1801K, 18% free 9661K/11655K, paused 2ms+2ms

1 个答案:

答案 0 :(得分:0)

你的滞后原因可能是你日志中的这些GC调用。

  

GC_CONCURRENT 当堆太大而无法阻止时调用   溢出。

     

时间显示暂停2ms + 2ms - 表示花了多少时间   GC完成收集

我建议转储你的hprof文件,转换它并通过MAT分析它来识别你的记忆累积点。在下面找到一篇关于如何做的非常好的文章。

http://developer.samsung.com/android/technical-docs/Memory-Profiler-Identifying-Potential-Problems

相关问题