Java 类android.view.ViewTreeObserver.OnDrawListener 实例源码

项目:silent-contacts-android    文件:SchedulingUtils.java   
/** Runs a piece of code just before the next draw. */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public static void doAfterDraw(final View view, final Runnable runnable) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN)
        return;

    final OnDrawListener listener = new OnDrawListener() {
        @Override
        public void onDraw() {
            view.getViewTreeObserver().removeOnDrawListener(this);
            runnable.run();
        }
    };
    view.getViewTreeObserver().addOnDrawListener(listener);
}