Java Code Examples for android.text.Layout#getHeight()

The following examples show how to use android.text.Layout#getHeight() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScrollTextView.java    From a with GNU General Public License v3.0 6 votes vote down vote up
private void initOffsetHeight() {
    int paddingTop;
    int paddingBottom;
    int mHeight;
    int mLayoutHeight;

    //获得内容面板
    Layout mLayout = getLayout();
    if (mLayout == null) return;
    //获得内容面板的高度
    mLayoutHeight = mLayout.getHeight();
    //获取上内边距
    paddingTop = getTotalPaddingTop();
    //获取下内边距
    paddingBottom = getTotalPaddingBottom();

    //获得控件的实际高度
    mHeight = getMeasuredHeight();

    //计算滑动距离的边界
    mOffsetHeight = mLayoutHeight + paddingTop + paddingBottom - mHeight;
    if (mOffsetHeight <= 0) {
        scrollTo(0, 0);
    }
}
 
Example 2
Source File: ScrollTextView.java    From MyBookshelf with GNU General Public License v3.0 6 votes vote down vote up
private void initOffsetHeight() {
    int paddingTop;
    int paddingBottom;
    int mHeight;
    int mLayoutHeight;

    //获得内容面板
    Layout mLayout = getLayout();
    if (mLayout == null) return;
    //获得内容面板的高度
    mLayoutHeight = mLayout.getHeight();
    //获取上内边距
    paddingTop = getTotalPaddingTop();
    //获取下内边距
    paddingBottom = getTotalPaddingBottom();

    //获得控件的实际高度
    mHeight = getMeasuredHeight();

    //计算滑动距离的边界
    mOffsetHeight = mLayoutHeight + paddingTop + paddingBottom - mHeight;
    if (mOffsetHeight <= 0) {
        scrollTo(0, 0);
    }
}
 
Example 3
Source File: WXText.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
/**
 * Flush view no matter what height and width the {@link WXDomObject} specifies.
 * @param extra must be a {@link Layout} object, otherwise, nothing will happen.
 */
private void flushView(Object extra) {
  if (extra instanceof Layout &&
      getHostView() != null && !extra.equals(getHostView().getTextLayout())) {
    final Layout layout = (Layout) extra;
    /**The following if block change the height of the width of the textView.
     * other part of the code is the same to updateExtra
     */
    ViewGroup.LayoutParams layoutParams = getHostView().getLayoutParams();
    if (layoutParams != null) {
      layoutParams.height = layout.getHeight();
      layoutParams.width = layout.getWidth();
      getHostView().setLayoutParams(layoutParams);
    }
    getHostView().setTextLayout(layout);
    getHostView().invalidate();
  }
}
 
Example 4
Source File: WXText.java    From weex-uikit with MIT License 6 votes vote down vote up
/**
 * Flush view no matter what height and width the {@link WXDomObject} specifies.
 * @param extra must be a {@link Layout} object, otherwise, nothing will happen.
 */
private void flushView(Object extra) {
  if (extra instanceof Layout &&
      getHostView() != null && !extra.equals(getHostView().getTextLayout())) {
    final Layout layout = (Layout) extra;
    /**The following if block change the height of the width of the textView.
     * other part of the code is the same to updateExtra
     */
    ViewGroup.LayoutParams layoutParams = getHostView().getLayoutParams();
    if (layoutParams != null) {
      layoutParams.height = layout.getHeight();
      layoutParams.width = layout.getWidth();
      getHostView().setLayoutParams(layoutParams);
    }
    getHostView().setTextLayout(layout);
    getHostView().invalidate();
  }
}
 
Example 5
Source File: LayoutMeasureUtil.java    From TextLayoutBuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Prior to version 20, If the Layout specifies extra space between lines (either by spacingmult
 * or spacingadd) the StaticLayout would erroneously add this space after the last line as well.
 * This bug was fixed in version 20. This method calculates the extra space and reduces the height
 * by that amount.
 *
 * @param layout The layout.
 * @return The height of the layout.
 */
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;
}
 
Example 6
Source File: TableRowSpan.java    From Markwon with Apache License 2.0 5 votes vote down vote up
@Override
public int getSize(
        @NonNull Paint paint,
        CharSequence text,
        @IntRange(from = 0) int start,
        @IntRange(from = 0) int end,
        @Nullable Paint.FontMetricsInt fm) {

    // it's our absolute requirement to have width of the canvas here... because, well, it changes
    // the way we draw text. So, if we do not know the width of canvas we cannot correctly measure our text

    if (layouts.size() > 0) {

        if (fm != null) {

            int max = 0;
            for (Layout layout : layouts) {
                final int height = layout.getHeight();
                if (height > max) {
                    max = height;
                }
            }

            // we store actual height
            height = max;

            // but apply height with padding
            final int padding = theme.tableCellPadding() * 2;

            fm.ascent = -(max + padding);
            fm.descent = 0;

            fm.top = fm.ascent;
            fm.bottom = 0;
        }
    }

    return width;
}
 
Example 7
Source File: MultiLineTexture.java    From PhotoMovie with Apache License 2.0 4 votes vote down vote up
private MultiLineTexture(Layout layout) {
    super(layout.getWidth(), layout.getHeight());
    mLayout = layout;
}