on View Pre Draw - Android User Interface

Android examples for User Interface:View

Description

on View Pre Draw

Demo Code


//package com.java2s;
import android.view.View;
import android.view.ViewTreeObserver;

public class Main {
    public static void onPreDraw(final View view,
            final ViewTreeObserver.OnPreDrawListener listener) {
        view.getViewTreeObserver().addOnPreDrawListener(
                new ViewTreeObserver.OnPreDrawListener() {
                    @Override/*  w  w w.  j a v  a 2  s .  c om*/
                    public boolean onPreDraw() {
                        if (view.getViewTreeObserver().isAlive()) {
                            view.getViewTreeObserver()
                                    .removeOnPreDrawListener(this);
                        }
                        return listener.onPreDraw();
                    }
                });
    }
}

Related Tutorials