@Nullable
    public static Pair<Integer, Integer> getViewSize(final View view) {
        view.measure(0, 0);
        if (view.getMeasuredHeight() > 0 || view.getMeasuredWidth() > 0) {
            return new Pair<>(view.getMeasuredWidth(), view.getMeasuredHeight());
        }
        //try to get size from layout parameters
        if (view.getLayoutParams() != null) {
            final int w = Math.max(view.getLayoutParams().width, 0);
            final int h = Math.max(view.getLayoutParams().height, 0);
            if (w > 0 || h > 0) {
                return new Pair<>(w, h);
            }
        }

        return null;

    }
Tries its best to return the size of a view. Returns null otherwise.
Sometimes it is only possible to return width OR height. In this case the other parameter is set to 0.

@return Pair where first is width in pixel and second is height in pixel
main/src/main/java/cgeo/geocaching/ui/ViewUtils.java