post Layout on View - Android User Interface

Android examples for User Interface:Layout

Description

post Layout on View

Demo Code


//package com.java2s;

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

public class Main {
    public static void postLayout(final View view, final Runnable runnable) {
        view.getViewTreeObserver().addOnGlobalLayoutListener(
                new ViewTreeObserver.OnGlobalLayoutListener() {

                    @Override// ww  w  .  java 2s .  c om
                    public void onGlobalLayout() {
                        //noinspection deprecation
                        view.getViewTreeObserver()
                                .removeGlobalOnLayoutListener(this);
                        view.post(runnable);
                    }

                });
    }
}

Related Tutorials