android.text.Layout#getHeight ( )源码实例Demo

下面列出了android.text.Layout#getHeight ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: a   文件: ScrollTextView.java
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);
    }
}
 
源代码2 项目: MyBookshelf   文件: ScrollTextView.java
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);
    }
}
 
源代码3 项目: ucar-weex-core   文件: WXText.java
/**
 * 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();
  }
}
 
源代码4 项目: weex-uikit   文件: WXText.java
/**
 * 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();
  }
}
 
源代码5 项目: TextLayoutBuilder   文件: LayoutMeasureUtil.java
/**
 * 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;
}
 
源代码6 项目: Markwon   文件: TableRowSpan.java
@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;
}
 
源代码7 项目: PhotoMovie   文件: MultiLineTexture.java
private MultiLineTexture(Layout layout) {
    super(layout.getWidth(), layout.getHeight());
    mLayout = layout;
}