public static void runOnViewMeasured(final View view, final Function<View, Boolean> action) {
        final ViewTreeObserver.OnGlobalLayoutListener observer = new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                if (view.getMeasuredWidth() > 0 && view.getMeasuredHeight() > 0) {
                    final Boolean continueAction = action.apply(view);
                    if (continueAction == null || !continueAction) {
                        view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                    }
                }
            }
        };

        //post the run in case "runOnViewMeasured" is used in a layouting context
        //(This is typically the case when it is used in Activity.onCreate)
        view.post(() -> {
            view.getViewTreeObserver().addOnGlobalLayoutListener(observer);
            view.requestLayout();
        });
    }
requests a layout change on given view and runs the given consumer once the view has been measured
main/src/main/java/cgeo/geocaching/ui/ViewUtils.java