生命周期的视图android

时间:2014-09-07 11:59:36

标签: android android-activity android-view android-lifecycle

我想在恢复活动后发生一些视图动画,但是在加载所有视图并且在加载所有视图之前(动画转换之前)开始动画之后,我无法捕捉时间。 我试图使用onDraw,onWindowFocusChange,onResume,我发现onDraw是视图生命周期中的最后一个方法,但我仍然看到动画在用户看到所有视图之前开始

3 个答案:

答案 0 :(得分:1)

除非视图具有生命周期,否则请考虑使用Fragment而不是视图作为片段。生命周期与它们嵌入的活动绑定。

另请参阅:What is the benefit of using Fragments in Android, rather than Views?

修改

尝试延迟开始动画:

new Handler().post(new Runnable() {
    @Override
    public void run() {
        // Start your animation here.
    }
});

答案 1 :(得分:1)

这是Android Activity生命周期&在我的设备上测试的Android View生命周期(Sony Z1 Compact)

Start an Activity
    Activity: onCreate
    Activity: onStart
    Activity: onResume
    View: onAttachedToWindow
    View: onWindowFocusChanged true
    # Running
    Activity: onPause
    View: onWindowFocusChanged false
    # Start to another Activity
    # Back from another Activity
    Activity: onResume
    View: onWindowFocusChanged true
    # Running
    View: onWindowFocusChanged false
    Activity: onPause
    Activity: onStop
    Activity: onDestroy
    View: onDetachedFromWindow

Turn Off Screen
    Activity: onCreate
    Activity: onStart
    Activity: onResume
    View: onAttachedToWindow
    View: onWindowFocusChanged true
    # Running
    Activity: onPause
    Activity: onStop
    View: onWindowFocusChanged false
    # Turn Off Screen
    # Turn On Screen
    Activity: onStart
    Activity: onResume
    View: onWindowFocusChanged true
    # Running
    View: onWindowFocusChanged false
    Activity: onPause
    Activity: onStop
    Activity: onDestroy
    View: onDetachedFromWindow

Switch Application
    Activity: onCreate
    Activity: onStart
    Activity: onResume
    View: onAttachedToWindow
    View: onWindowFocusChanged true
    # Running
    Activity: onPause
    View: onWindowFocusChanged false
    Activity: onStop
    # Switch to Application
    # Back from Application
    Activity: onStart
    Activity: onResume
    View: onWindowFocusChanged true
    # Running
    Activity: onPause
    View: onWindowFocusChanged false
    Activity: onStop
    Activity: onDestroy
    View: onDetachedFromWindow

答案 2 :(得分:0)

您可以创建启动活动。在此启动活动中,您可以显示动画。

How do I make a splash screen?

如果您需要在显示动画时计算某事,请使用线程计算并将其发送到您的主要活动

How do I pass data between Activities in Android application?