android.text.Layout.getHeight()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(10.7k)|赞(0)|评价(0)|浏览(154)

本文整理了Java中android.text.Layout.getHeight()方法的一些代码示例,展示了Layout.getHeight()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Layout.getHeight()方法的具体详情如下:
包路径:android.text.Layout
类名称:Layout
方法名:getHeight

Layout.getHeight介绍

暂无

代码示例

代码示例来源:origin: weexteam/weex-hackernews

@Override
 public void measure(CSSNode node, float width, @NonNull MeasureOutput measureOutput) {
  WXTextDomObject textDomObject = (WXTextDomObject) node;
  if (CSSConstants.isUndefined(width)) {
   width = node.cssstyle.maxWidth;
  }
  if(textDomObject.getTextWidth(textDomObject.mTextPaint,width,false)>0) {
   textDomObject.layout = textDomObject.createLayout(width, false, null);
   textDomObject.hasBeenMeasured = true;
   textDomObject.previousWidth = textDomObject.layout.getWidth();
   measureOutput.height = textDomObject.layout.getHeight();
   measureOutput.width = textDomObject.previousWidth;
  }else{
   measureOutput.height = 0;
   measureOutput.width = 0;
  }
 }
};

代码示例来源:origin: weexteam/weex-hackernews

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
 super.onSizeChanged(w, h, oldw, oldh);
 int contentH = getLayout().getHeight();
 //TODO: known issue,set movement to null will make cursor disappear.
 if(h < contentH){
  setMovementMethod(null);
 }else{
  setMovementMethod(getDefaultMovementMethod());
 }
}

代码示例来源:origin: facebook/TextLayoutBuilder

/**
 * 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;
}

代码示例来源:origin: sjwall/MaterialTapTargetPrompt

@Override
  void createTextLayout(@NonNull final PromptOptions options, final float maxWidth, final float alphaModifier)
  {
    super.createTextLayout(options, maxWidth, alphaModifier);
    if (mPrimaryTextLayout != null)
    {
      mPrimaryTextLayout = spy(mPrimaryTextLayout);
      when(mPrimaryTextLayout.getLineWidth(0)).thenReturn(mMaxTextWidth);
      when(mPrimaryTextLayout.getHeight()).thenReturn(200);
      if (mRtl)
      {
        when(mPrimaryTextLayout.getAlignment()).thenReturn(Layout.Alignment.ALIGN_OPPOSITE);
      }
    }
    if (mSecondaryTextLayout != null)
    {
      mSecondaryTextLayout = spy(mSecondaryTextLayout);
      when(mSecondaryTextLayout.getLineWidth(0)).thenReturn(mMaxTextWidth);
      when(mSecondaryTextLayout.getHeight()).thenReturn(200);
      if (mRtl)
      {
        when(mSecondaryTextLayout.getAlignment()).thenReturn(Layout.Alignment.ALIGN_OPPOSITE);
      }
    }
  }
}

代码示例来源:origin: weexteam/weex-hackernews

/**
 * 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();
 }
}

代码示例来源:origin: sjwall/MaterialTapTargetPrompt

if (mPrimaryTextLayout != null)
    mPrimaryTextTop -= mPrimaryTextLayout.getHeight();
if (mPrimaryTextLayout != null)
  primaryTextHeight = mPrimaryTextLayout.getHeight();
  textHeight = mSecondaryTextLayout.getHeight();
  if (verticalTextPositionAbove)

代码示例来源:origin: grzegorznittner/chanu

private MultiLineTexture(Layout layout) {
  super(layout.getWidth(), layout.getHeight());
  mLayout = layout;
}

代码示例来源:origin: stackoverflow.com

Bitmap mBitmap;
   Layout webViewContainer
   mBitmap =  Bitmap.createBitmap(webViewContainer.getWidth(), webViewContainer.getHeight(), Bitmap.Config.ARGB_8888);
   Canvas canvas = new Canvas(mBitmap);
   webViewContainer.draw(canvas);

代码示例来源:origin: gumingwei/WellSwipe

private int measureHeight(int heightMeasureSpec) {
  int heightMode = MeasureSpec.getMode(heightMeasureSpec);
  int heightSize = MeasureSpec.getSize(heightMeasureSpec);
  int measuredHeight;
  int minHeight = (int) Math.max(mThumbSizeF.y, mThumbSizeF.y + mThumbMargin.top + mThumbMargin.right);
  float onHeight = mOnLayout != null ? mOnLayout.getHeight() : 0;
  float offHeight = mOffLayout != null ? mOffLayout.getHeight() : 0;
  if (onHeight != 0 || offHeight != 0) {
    mTextHeight = Math.max(onHeight, offHeight);
    minHeight = (int) Math.max(minHeight, mTextHeight);
  }
  minHeight = Math.max(minHeight, getSuggestedMinimumHeight());
  minHeight = Math.max(minHeight, minHeight + getPaddingTop() + getPaddingBottom());
  if (heightMode == MeasureSpec.EXACTLY) {
    measuredHeight = Math.max(minHeight, heightSize);
  } else {
    measuredHeight = minHeight;
    if (heightMode == MeasureSpec.AT_MOST) {
      measuredHeight = Math.min(measuredHeight, heightSize);
    }
  }
  return measuredHeight;
}

代码示例来源:origin: tiandawu/IotXmpp

private int measureHeight(int heightMeasureSpec) {
  int heightMode = MeasureSpec.getMode(heightMeasureSpec);
  int heightSize = MeasureSpec.getSize(heightMeasureSpec);
  int measuredHeight;
  int minHeight = (int) Math.max(mThumbSizeF.y, mThumbSizeF.y + mThumbMargin.top + mThumbMargin.right);
  float onHeight = mOnLayout != null ? mOnLayout.getHeight() : 0;
  float offHeight = mOffLayout != null ? mOffLayout.getHeight() : 0;
  if (onHeight != 0 || offHeight != 0) {
    mTextHeight = Math.max(onHeight, offHeight);
    minHeight = (int) Math.max(minHeight, mTextHeight);
  }
  minHeight = Math.max(minHeight, getSuggestedMinimumHeight());
  minHeight = Math.max(minHeight, minHeight + getPaddingTop() + getPaddingBottom());
  if (heightMode == MeasureSpec.EXACTLY) {
    measuredHeight = Math.max(minHeight, heightSize);
  } else {
    measuredHeight = minHeight;
    if (heightMode == MeasureSpec.AT_MOST) {
      measuredHeight = Math.min(measuredHeight, heightSize);
    }
  }
  return measuredHeight;
}

代码示例来源:origin: sealtalk/sealtalk-android

private int measureHeight(int heightMeasureSpec) {
  int heightMode = MeasureSpec.getMode(heightMeasureSpec);
  int heightSize = MeasureSpec.getSize(heightMeasureSpec);
  int measuredHeight;
  int minHeight = (int) Math.max(mThumbSizeF.y, mThumbSizeF.y + mThumbMargin.top + mThumbMargin.right);
  float onHeight = mOnLayout != null ? mOnLayout.getHeight() : 0;
  float offHeight = mOffLayout != null ? mOffLayout.getHeight() : 0;
  if (onHeight != 0 || offHeight != 0) {
    mTextHeight = Math.max(onHeight, offHeight);
    minHeight = (int) Math.max(minHeight, mTextHeight);
  }
  minHeight = Math.max(minHeight, getSuggestedMinimumHeight());
  minHeight = Math.max(minHeight, minHeight + getPaddingTop() + getPaddingBottom());
  if (heightMode == MeasureSpec.EXACTLY) {
    measuredHeight = Math.max(minHeight, heightSize);
  } else {
    measuredHeight = minHeight;
    if (heightMode == MeasureSpec.AT_MOST) {
      measuredHeight = Math.min(measuredHeight, heightSize);
    }
  }
  return measuredHeight;
}

代码示例来源:origin: gumingwei/WellSwipe

float marginOnY = mBackRectF.top + (mBackRectF.height() - mOnLayout.getHeight()) / 2;
mTextOnRectF.set(marginOnX, marginOnY, marginOnX + mOnLayout.getWidth(), marginOnY + mOnLayout.getHeight());
float marginOffY = mBackRectF.top + (mBackRectF.height() - mOnLayout.getHeight()) / 2;
mTextOffRectF.set(marginOffX, marginOffY, marginOffX + mOffLayout.getWidth(), marginOffY + mOffLayout.getHeight());

代码示例来源:origin: sealtalk/sealtalk-android

float marginOnY = mBackRectF.top + (mBackRectF.height() - mOnLayout.getHeight()) / 2;
mTextOnRectF.set(marginOnX, marginOnY, marginOnX + mOnLayout.getWidth(), marginOnY + mOnLayout.getHeight());
float marginOffY = mBackRectF.top + (mBackRectF.height() - mOffLayout.getHeight()) / 2;
mTextOffRectF.set(marginOffX, marginOffY, marginOffX + mOffLayout.getWidth(), marginOffY + mOffLayout.getHeight());

代码示例来源:origin: ahmadaghazadeh/CodeEditor

private void getMeasurements() {
  if(mEditor != null && mEditor.getLayout() != null) {
    mViewHeight = getHeight();
    mScrollMax = mEditor.getLayout().getHeight();
    mScrollY = mEditor.getScrollY();
    mEditor.getHeight();
    mEditor.getLayout().getHeight();
    mThumbTop = getThumbTop();
  }
}

代码示例来源:origin: Light-Team/ModPE-IDE-Source

private void getMeasurements() {
  if(mEditor != null && mEditor.getLayout() != null) {
    mViewHeight = getHeight();
    mScrollMax = mEditor.getLayout().getHeight();
    mScrollY = mEditor.getScrollY();
    mEditor.getHeight();
    mEditor.getLayout().getHeight();
    mThumbTop = getThumbTop();
  }
}

代码示例来源:origin: sunfusheng/GroupRecyclerViewAdapter

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  /*
   * ensure textLayout
   */
  if (mOnLayout == null && !TextUtils.isEmpty(mTextOn)) {
    mOnLayout = makeLayout(mTextOn);
  }
  if (mOffLayout == null && !TextUtils.isEmpty(mTextOff)) {
    mOffLayout = makeLayout(mTextOff);
  }
  float onWidth = mOnLayout != null ? mOnLayout.getWidth() : 0;
  float offWidth = mOffLayout != null ? mOffLayout.getWidth() : 0;
  if (onWidth != 0 || offWidth != 0) {
    mTextWidth = Math.max(onWidth, offWidth);
  } else {
    mTextWidth = 0;
  }
  float onHeight = mOnLayout != null ? mOnLayout.getHeight() : 0;
  float offHeight = mOffLayout != null ? mOffLayout.getHeight() : 0;
  if (onHeight != 0 || offHeight != 0) {
    mTextHeight = Math.max(onHeight, offHeight);
  } else {
    mTextHeight = 0;
  }
  setMeasuredDimension(measureWidth(widthMeasureSpec), measureHeight(heightMeasureSpec));
}

代码示例来源:origin: THEONE10211024/ApiDemos

@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  if (mOnLayout == null) {
    mOnLayout = makeLayout(mTextOn);
  }
  if (mOffLayout == null) {
    mOffLayout = makeLayout(mTextOff);
  }
  final int minWidth = Math.max(mOnLayout.getWidth(), mOffLayout.getWidth())
      + getPaddingLeft() + getPaddingRight();
  final int minHeight = Math.max(mOnLayout.getHeight(), mOffLayout.getHeight())
      + getPaddingLeft() + getPaddingRight();
  setMeasuredDimension(resolveSizeAndState(minWidth, widthMeasureSpec, 0),
      resolveSizeAndState(minHeight, heightMeasureSpec, 0));
}

代码示例来源:origin: qiubiteme/android_api_demos

@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  if (mOnLayout == null) {
    mOnLayout = makeLayout(mTextOn);
  }
  if (mOffLayout == null) {
    mOffLayout = makeLayout(mTextOff);
  }
  final int minWidth = Math.max(mOnLayout.getWidth(), mOffLayout.getWidth())
      + getPaddingLeft() + getPaddingRight();
  final int minHeight = Math.max(mOnLayout.getHeight(), mOffLayout.getHeight())
      + getPaddingLeft() + getPaddingRight();
  setMeasuredDimension(resolveSizeAndState(minWidth, widthMeasureSpec, 0),
      resolveSizeAndState(minHeight, heightMeasureSpec, 0));
}

代码示例来源:origin: Y-bao/PullRefreshView

@Override
public boolean canOverEnd() {
  if (getScrollY() >= (getLayout().getHeight() - getMeasuredHeight() + getCompoundPaddingBottom() + getCompoundPaddingTop()))
    return true;
  else
    return false;
}

代码示例来源:origin: Y-bao/PullRefreshView

@Override
  public void scrollAViewBy(int dp) {
    int maxScrollY = (getLayout().getHeight() - getMeasuredHeight() + getCompoundPaddingBottom() + getCompoundPaddingTop());
    if (getScrollY() + dp >= maxScrollY) {
      scrollTo(0, maxScrollY);
    } else {
      scrollBy(0, dp);
    }
  }
}

相关文章