public static int getWidth(Layout layout) {
    if (layout == null) {
      return 0;
    }

    // Supplying VERY_WIDE will make layout.getWidth() return a very large value.
    int count = layout.getLineCount();
    int maxWidth = 0;

    for (int i = 0; i < count; i++) {
      maxWidth = Math.max(maxWidth, (int) layout.getLineRight(i));
    }

    return maxWidth;
  }
Returns the width of the layout.

@param layout The layout.
@return The width of the layout.
library/src/main/java/com/facebook/fbui/textlayoutbuilder/util/LayoutMeasureUtil.java