Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.annotation.SuppressLint;

import android.os.Build;
import android.view.View;
import android.view.ViewTreeObserver;

public class Main {
    public static void addGlobalLayoutRequest(final View v, final Runnable runnable) {
        v.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            public void onGlobalLayout() {
                if (runnable != null)
                    runnable.run();

                removeOnGlobalLayoutListener(v, this);
            }
        });

        v.requestLayout();
    }

    @SuppressLint("NewApi")
    public static void removeOnGlobalLayoutListener(View v, ViewTreeObserver.OnGlobalLayoutListener listener) {
        if (Build.VERSION.SDK_INT < 16)
            v.getViewTreeObserver().removeGlobalOnLayoutListener(listener);
        else
            v.getViewTreeObserver().removeOnGlobalLayoutListener(listener);
    }
}