android.widget.TextView.getMeasuredHeight()方法的使用及代码示例

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

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

TextView.getMeasuredHeight介绍

暂无

代码示例

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

public static int getHeight(Context context, String text, int textSize, int deviceWidth) {
  TextView textView = new TextView(context);
  textView.setText(text);
  textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
  int widthMeasureSpec = MeasureSpec.makeMeasureSpec(deviceWidth, MeasureSpec.AT_MOST);
  int heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
  textView.measure(widthMeasureSpec, heightMeasureSpec);
  return textView.getMeasuredHeight();
}

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

public static int getHeight(Context context, CharSequence text, int textSize, int deviceWidth, Typeface typeface,int padding) {
     TextView textView = new TextView(context);
     textView.setPadding(padding,0,padding,padding);
     textView.setTypeface(typeface);
     textView.setText(text, TextView.BufferType.SPANNABLE);
     textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);
     int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(deviceWidth, View.MeasureSpec.AT_MOST);
     int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
     textView.measure(widthMeasureSpec, heightMeasureSpec);
     return textView.getMeasuredHeight();
   }

代码示例来源:origin: jaydenxiao2016/AndroidFire

/**
 * 设置移动距离
 *
 * @param dis
 */
public void setDistance(int dis) {
  mDistance = dis;
  mToY = dis;
  mChanged = true;
  setHeight(mDistance + mGood.getMeasuredHeight());
}

代码示例来源:origin: jaydenxiao2016/AndroidFire

private static int getTextViewHeight(TextView textView, int width) {
  int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.AT_MOST);
  int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
  textView.measure(widthMeasureSpec, heightMeasureSpec);
  return textView.getMeasuredHeight();
}

代码示例来源:origin: rey5137/material

childTop = (childBottom - mNameView.getMeasuredHeight() - mAddressView.getMeasuredHeight()) / 2;
  mNameView.layout(childLeft, childTop, childRight - mSpacing, childTop + mNameView.getMeasuredHeight());
  childTop += mNameView.getMeasuredHeight();
  mAddressView.layout(childLeft, childTop, childRight - mSpacing, childTop + mAddressView.getMeasuredHeight());
  childTop = (childBottom - mNameView.getMeasuredHeight()) / 2;
  mNameView.layout(childLeft, childTop, childRight - mSpacing, childTop + mNameView.getMeasuredHeight());
childTop = (childBottom - mAddressView.getMeasuredHeight()) / 2;
mAddressView.layout(childLeft, childTop, childRight - mSpacing, childTop + mAddressView.getMeasuredHeight());

代码示例来源:origin: fython/MaterialStepperView

@Override
  public void onGlobalLayout() {
    int singleLineHeight = mTitleText.getMeasuredHeight();
    int topMargin = (mPointFrame.getMeasuredHeight() - singleLineHeight) / 2;
    // Only update top margin when it is positive, preventing titles being truncated.
    if (topMargin > 0) {
      ViewGroup.MarginLayoutParams mlp = (MarginLayoutParams) mTitleText.getLayoutParams();
      mlp.topMargin = topMargin;
    }
  }
});

代码示例来源:origin: qiujuer/Genius-Android

public void resetSizes(String maxValue) {
  DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
  //Account for negative numbers... is there any proper way of getting the biggest string between our range????
  mNumber.setText(String.format("-%s", maxValue));
  //Do a first forced measure call for the TextView (with the biggest text content),
  //to calculate the max width and use always the same.
  //this avoids the TextView from shrinking and growing when the text content changes
  int wSpec = MeasureSpec.makeMeasureSpec(displayMetrics.widthPixels, MeasureSpec.AT_MOST);
  int hSpec = MeasureSpec.makeMeasureSpec(displayMetrics.heightPixels, MeasureSpec.AT_MOST);
  mNumber.measure(wSpec, hSpec);
  mWidth = Math.max(mNumber.getMeasuredWidth(), mNumber.getMeasuredHeight());
  removeView(mNumber);
  addView(mNumber, new FrameLayout.LayoutParams(mWidth, mWidth, Gravity.LEFT | Gravity.TOP));
}

代码示例来源:origin: rey5137/material

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  int widthMode = MeasureSpec.getMode(widthMeasureSpec);
  int widthSize = MeasureSpec.getSize(widthMeasureSpec);
  int heightMode = MeasureSpec.getMode(heightMeasureSpec);
  int heightSize = MeasureSpec.getSize(heightMeasureSpec);
  int nonTextWidth = mAvatarSize + mSpacing * 3 + mButtonSize;
  int ws = MeasureSpec.makeMeasureSpec(widthSize - nonTextWidth, widthMode == MeasureSpec.UNSPECIFIED ? widthMode : MeasureSpec.AT_MOST);
  int hs = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
  mNameView.measure(ws, hs);
  mAddressView.measure(ws, hs);
  if(mButton != null)
    mButton.measure(MeasureSpec.makeMeasureSpec(mButtonSize, MeasureSpec.EXACTLY), hs);
  int width = widthMode == MeasureSpec.EXACTLY ? widthSize : Math.max(mNameView.getMeasuredWidth(), mAddressView.getMeasuredWidth()) + nonTextWidth;
  int height = Math.max(mAvatarSize + mSpacing * 2, mNameView.getMeasuredHeight() + mAddressView.getMeasuredHeight());
  switch (heightMode){
    case MeasureSpec.EXACTLY:
      height = heightSize;
      break;
    case MeasureSpec.AT_MOST:
      height = Math.min(height, heightSize);
      break;
  }
  height = Math.max(mMinHeight, height);
  if(mButton != null)
    mButton.measure(MeasureSpec.makeMeasureSpec(mButtonSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
  setMeasuredDimension(width, height);
}

代码示例来源:origin: jaydenxiao2016/AndroidFire

private void initView() {
  RelativeLayout layout = new RelativeLayout(mContext);
  RelativeLayout.LayoutParams params =
      new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
          RelativeLayout.LayoutParams.WRAP_CONTENT);
  params.addRule(RelativeLayout.CENTER_HORIZONTAL);
  params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
  mGood = new TextView(mContext);
  mGood.setIncludeFontPadding(false);
  mGood.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mTextSize);
  mGood.setTextColor(ContextCompat.getColor(mContext, mTextColor));
  mGood.setText(mText);
  mGood.setLayoutParams(params);
  layout.addView(mGood);
  setContentView(layout);
  int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
  int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
  mGood.measure(w, h);
  setWidth(mGood.getMeasuredWidth());
  setHeight(mDistance + mGood.getMeasuredHeight());
  setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
  setFocusable(false);
  setTouchable(false);
  setOutsideTouchable(false);
  mAnimationSet = createAnimation();
}

代码示例来源:origin: lipangit/JiaoZiVideoPlayer

layout.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
  int offsetX = clarity.getMeasuredWidth() / 3;
  int offsetY = clarity.getMeasuredHeight() / 3;
  clarityPopWindow.update(clarity, -offsetX, -offsetY, Math.round(layout.getMeasuredWidth() * 2), layout.getMeasuredHeight());
} else if (i == R.id.retry_btn) {

代码示例来源:origin: venshine/GoodView

private static int getTextViewHeight(TextView textView, int width) {
  int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.AT_MOST);
  int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
  textView.measure(widthMeasureSpec, heightMeasureSpec);
  return textView.getMeasuredHeight();
}

代码示例来源:origin: venshine/GoodView

/**
 * 设置移动距离
 *
 * @param dis
 */
public void setDistance(int dis) {
  mDistance = dis;
  mToY = dis;
  mChanged = true;
  setHeight(mDistance + mGood.getMeasuredHeight());
}

代码示例来源:origin: google/santa-tracker-android

public static void fitToBounds(TextView textView, float widthPx, float heightPx) {
  textView.measure(0, 0);
  float currentWidthPx = textView.getMeasuredWidth();
  float currentHeightPx = textView.getMeasuredHeight();
  float textSize = textView.getTextSize();
  float scale = Math.min(widthPx / currentWidthPx, heightPx / currentHeightPx);
  textView.setTextSize(textSize * scale);
}

代码示例来源:origin: venshine/GoodView

private void initView() {
  RelativeLayout layout = new RelativeLayout(mContext);
  RelativeLayout.LayoutParams params =
      new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
          RelativeLayout.LayoutParams.WRAP_CONTENT);
  params.addRule(RelativeLayout.CENTER_HORIZONTAL);
  params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
  mGood = new TextView(mContext);
  mGood.setIncludeFontPadding(false);
  mGood.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mTextSize);
  mGood.setTextColor(mTextColor);
  mGood.setText(mText);
  mGood.setLayoutParams(params);
  layout.addView(mGood);
  setContentView(layout);
  int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
  int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
  mGood.measure(w, h);
  setWidth(mGood.getMeasuredWidth());
  setHeight(mDistance + mGood.getMeasuredHeight());
  setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
  setFocusable(false);
  setTouchable(false);
  setOutsideTouchable(false);
  mAnimationSet = createAnimation();
}

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

float height = view.getMeasuredHeight();

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

LinearLayout container = (LinearLayout) findViewById(R.id.container);
final TextView first = (TextView) findViewById(R.id.first);
final TextView second = (TextView) findViewById(R.id.second);

container.post(new Runnable() {
  @Override public void run() {
    int h1 = first.getMeasuredHeight();
    int h2 = second.getMeasuredHeight();
    if (h1 < h2) first.getLayoutParams().height = h2;

  }
});

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

public static void expandCollapsedByMaxLines(@NonNull final TextView text) {
  final int height = text.getMeasuredHeight();
  text.setHeight(height);
  text.setMaxLines(Integer.MAX_VALUE); //expand fully
  text.measure(View.MeasureSpec.makeMeasureSpec(text.getMeasuredWidth(), View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(ViewGroup.LayoutParams.WRAP_CONTENT, View.MeasureSpec.UNSPECIFIED));
  final int newHeight = text.getMeasuredHeight();
  ObjectAnimator animation = ObjectAnimator.ofInt(text, "height", height, newHeight);
  animation.setDuration(250).start();
}

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

TextView upTextView = (TextView) getLayoutInflater().inflate(
    R.layout.up_text, null);
upTextView.setText("CITIES");
upTextView.measure(0, 0);
upTextView.layout(0, 0, upTextView.getMeasuredWidth(), 
    upTextView.getMeasuredHeight());
Bitmap bitmap = Bitmap.createBitmap(upTextView.getMeasuredWidth(),
    upTextView.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
upTextView.draw(canvas);
BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), bitmap);

代码示例来源:origin: L4Digital/FastScroll

private void updateViewHeights() {
  int measureSpec = MeasureSpec.makeMeasureSpec(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
  bubbleView.measure(measureSpec, measureSpec);
  bubbleHeight = bubbleView.getMeasuredHeight();
  handleView.measure(measureSpec, measureSpec);
  handleHeight = handleView.getMeasuredHeight();
}

代码示例来源:origin: L4Digital/FastScroll

private void setViewPositions(float y) {
  bubbleHeight = bubbleView.getMeasuredHeight();
  handleHeight = handleView.getMeasuredHeight();
  int bubbleY = getValueInRange(0, viewHeight - bubbleHeight - handleHeight / 2, (int) (y - bubbleHeight));
  int handleY = getValueInRange(0, viewHeight - handleHeight, (int) (y - handleHeight / 2));
  if (showBubble) {
    bubbleView.setY(bubbleY);
  }
  handleView.setY(handleY);
}

相关文章

TextView类方法