Remove a previously installed global layout callback. - Android User Interface

Android examples for User Interface:Layout

Description

Remove a previously installed global layout callback.

Demo Code


//package com.java2s;
import android.annotation.SuppressLint;
import android.os.Build;
import android.view.View;
import android.view.ViewTreeObserver;

public class Main {
    /**/*from  w  w  w  . java  2s .c o  m*/
     * Remove a previously installed global layout callback.
     *
     * @param v The View.
     * @param listener The callback to remove.
     * @see #addGlobalLayoutListener(View, ViewTreeObserver.OnGlobalLayoutListener).
     */
    @SuppressWarnings("deprecation")
    @SuppressLint("NewApi")
    public static void removeGlobalLayoutListener(View v,
            ViewTreeObserver.OnGlobalLayoutListener listener) {
        ViewTreeObserver observer = v.getViewTreeObserver();
        if (observer == null || !observer.isAlive()) {
            return;
        }

        if (Build.VERSION.SDK_INT < 16) {
            observer.removeGlobalOnLayoutListener(listener);
        } else {
            observer.removeOnGlobalLayoutListener(listener);
        }
    }
}

Related Tutorials