Register a callback to be invoked when the global layout state or the visibility of views within the view tree changes. - Android User Interface

Android examples for User Interface:Layout

Description

Register a callback to be invoked when the global layout state or the visibility of views within the view tree changes.

Demo Code


//package com.java2s;

import android.view.View;
import android.view.ViewTreeObserver;

public class Main {
    /**/*from   w w  w  . j av  a 2  s . c  o  m*/
     * Register a callback to be invoked when the global layout state or the visibility of views
     * within the view tree changes.
     *
     * @param v The View.
     * @param listener The callback to add.
     * @see #removeGlobalLayoutListener(View, ViewTreeObserver.OnGlobalLayoutListener).
     */
    public static void addGlobalLayoutListener(View v,
            ViewTreeObserver.OnGlobalLayoutListener listener) {
        ViewTreeObserver observer = v.getViewTreeObserver();

        if (observer == null || !observer.isAlive()) {
            return;
        }

        observer.addOnGlobalLayoutListener(listener);
    }
}

Related Tutorials