LayoutMeasureUtil { public static int getHeight(Layout layout) { if (layout == null) { return 0; } int extra = 0; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT_WATCH && layout instanceof StaticLayout) { int line = Math.max(0, layout.getLineCount() - 1); int above = layout.getLineAscent(line); int below = layout.getLineDescent(line); float originalSize = (below - above - layout.getSpacingAdd()) / layout.getSpacingMultiplier(); float ex = below - above - originalSize; if (ex >= 0) { extra = (int) (ex + 0.5); } else { extra = -(int) (-ex + 0.5); } } return layout.getHeight() - extra; }  static int getWidth(Layout layout); static int getHeight(Layout layout); static int getContentLeft(Layout layout);  }
@Test public void testOneLineWithAdd() { mLayout = StaticLayoutHelper.makeStaticLayout(ONE_LINE_TEXT, 1.0f, 5.0f); assertEquals(LayoutMeasureUtil.getHeight(mLayout), 10); }
@Test public void testTwoLinesWithAdd() { mLayout = StaticLayoutHelper.makeStaticLayout(TWO_LINE_TEXT, 1.0f, 5.0f); assertEquals(LayoutMeasureUtil.getHeight(mLayout), 25); }
@Test public void testOneLineWithMulti() { mLayout = StaticLayoutHelper.makeStaticLayout(ONE_LINE_TEXT, 1.5f, 0.0f); assertEquals(LayoutMeasureUtil.getHeight(mLayout), 10); }
@Test public void testTwoLinesWithMulti() { mLayout = StaticLayoutHelper.makeStaticLayout(TWO_LINE_TEXT, 1.5f, 0.0f); assertEquals(LayoutMeasureUtil.getHeight(mLayout), 25); }
@Test public void testOneLineWithAddAndMulti() { mLayout = StaticLayoutHelper.makeStaticLayout(ONE_LINE_TEXT, 1.5f, 2.0f); assertEquals(LayoutMeasureUtil.getHeight(mLayout), 10); }
@Test public void testTwoLinesWithAddAndMulti() { mLayout = StaticLayoutHelper.makeStaticLayout(TWO_LINE_TEXT, 1.5f, 2.0f); assertEquals(LayoutMeasureUtil.getHeight(mLayout), 27); }
@Test public void testEmptyTextWithAddAndMulti() { mLayout = StaticLayoutHelper.makeStaticLayout("", 1.5f, 2.0f); assertEquals(LayoutMeasureUtil.getHeight(mLayout), 10); }