本文整理汇总了Java中android.widget.TextView.getMeasuredHeight方法的典型用法代码示例。如果您正苦于以下问题:Java TextView.getMeasuredHeight方法的具体用法?Java TextView.getMeasuredHeight怎么用?Java TextView.getMeasuredHeight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.TextView
的用法示例。
在下文中一共展示了TextView.getMeasuredHeight方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createLabelBitmap
import android.widget.TextView; //导入方法依赖的package包/类
public Bitmap createLabelBitmap(String label) {
if (DBG) Log.d(TAG, "createLabelBitmap : label="+ label);
mLabelView = (TextView)mLayoutInflater.inflate(R.layout.cover_roll_label, null);
mLabelView.setText(label);
mLabelView.setLayoutParams( new FrameLayout.LayoutParams(NO_SIZE_LIMIT,NO_SIZE_LIMIT) );
mLabelView.measure(NO_SIZE_LIMIT, NO_SIZE_LIMIT);
final int width = mLabelView.getMeasuredWidth();
final int height = mLabelView.getMeasuredHeight();
if(DBG) Log.d(TAG, "createLabelBitmap: mLabelView size = "+width+"x"+height);
mLabelView.layout(0, 0, width, height);
StaticLayout textLayout = null;
if (isRtlLabel()) {
// Archos hack : when a right-to-left language is selected calling TextView.draw()
// draws the background but not the text, so also call TextLayout.draw() which works
textLayout = createTextLayout(label, Color.LTGRAY, mContentLabelFontsize, width);
}
return createViewBitmap(mLabelView, textLayout, width, height, ALIGN_BOTTOM);
}
示例2: getHeight
import android.widget.TextView; //导入方法依赖的package包/类
/**
* 在绘制之前,测量 TextView 的高度
* @param context 上下文
* @param text 内容
* @param textSize sp
* @param deviceWidth TextView 所在容器的宽度[重要]
* @param typeface 加粗等等样式
* @param padding 内间距
* @return TextView 的高度
*/
public int getHeight(Context context, CharSequence text, int textSize, int deviceWidth, Typeface typeface, int padding) {
TextView textView = new TextView(context);
textView.setPadding(padding,padding,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();
}
示例3: getShortHeight
import android.widget.TextView; //导入方法依赖的package包/类
/**
* 要伸缩文本的高度 宽度固定的MeasureSpec.EXACTLY 高度MeasureSpec.AT_MOST
*
* @return
*/
public int getShortHeight() {
int measuredWidth = contentTextView.getMeasuredWidth();
TextView copyTextView = new TextView(getContext());
copyTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 8);
int widthMeasureSpec = MeasureSpec.makeMeasureSpec(measuredWidth, MeasureSpec.EXACTLY);
copyTextView.setMaxLines(3);//设置默认不展开的情况下显示3行
copyTextView.setLines(3);//文本设置3行 不够3行显示3行的高度
int heightMeasureSpec = MeasureSpec.makeMeasureSpec(2000, MeasureSpec.AT_MOST);
copyTextView.measure(widthMeasureSpec, heightMeasureSpec);
return copyTextView.getMeasuredHeight();
}
示例4: getTileHeight
import android.widget.TextView; //导入方法依赖的package包/类
/**
* Title的高度(更新 应用介绍 权限 这几个字) 宽度是固定的MeasureSpec.EXACTLY
*
* @return
*/
public int getTileHeight() {
int measuredWidth = titleTextView.getMeasuredWidth();
TextView copyTextView = new TextView(getContext());
copyTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
int widthMeasureSpec = MeasureSpec.makeMeasureSpec(measuredWidth, MeasureSpec.EXACTLY);
copyTextView.setMaxLines(1);
copyTextView.setLines(1);
int heightMeasureSpec = MeasureSpec.makeMeasureSpec(2000, MeasureSpec.AT_MOST);//MeasureSpec.AT_MOST情况下前一个参数设置多少无所谓
copyTextView.measure(widthMeasureSpec, heightMeasureSpec);
return copyTextView.getMeasuredHeight();
}
示例5: getHeight
import android.widget.TextView; //导入方法依赖的package包/类
/**
* 获取TextView的高度
* @param context
* @param text
* @param textSize
* @param deviceWidth
* @param typeface
* @param padding
* @return
*/
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();
}
示例6: measureTextViewHeight
import android.widget.TextView; //导入方法依赖的package包/类
/**
* 获取文本实际所占高度,辅助用于计算行高,行数
*
* @param text 文本
* @param textSize 字体大小
* @param deviceWidth 屏幕宽度
*/
private void measureTextViewHeight(String text, float textSize, int deviceWidth) {
TextView textView = new TextView(getContext());
textView.setText(text);
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
int widthMeasureSpec = MeasureSpec.makeMeasureSpec(deviceWidth, MeasureSpec.EXACTLY);
int heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
textView.measure(widthMeasureSpec, heightMeasureSpec);
originalLineCount = textView.getLineCount();
originalHeight = textView.getMeasuredHeight();
}
示例7: MeasureString
import android.widget.TextView; //导入方法依赖的package包/类
public static Point MeasureString(Context context, String text, float fontSize, int widthMeasureSpec, int heightMeasureSpec) {
int width = 0;
int height = 0;
if (null == context || null == text || text.isEmpty() || 0 == fontSize) {
return null;
}
TextView tv = new TextView(context);
tv.setText(text);// 待测文本
tv.setTextSize(fontSize);// 字体
if (ViewGroup.LayoutParams.WRAP_CONTENT != widthMeasureSpec && ViewGroup.LayoutParams.MATCH_PARENT != widthMeasureSpec) {
tv.setWidth(widthMeasureSpec);// 如果设置了宽度,字符串的宽度则为所设置的宽度
}
if (ViewGroup.LayoutParams.WRAP_CONTENT != heightMeasureSpec && ViewGroup.LayoutParams.MATCH_PARENT != heightMeasureSpec) {
tv.setHeight(heightMeasureSpec);
}
tv.setSingleLine(false);// 多行
tv.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
width = tv.getMeasuredWidth();
height = tv.getMeasuredHeight();
Point point = new Point();
point.x = width;
point.y = height;
return point;
}
示例8: setTvWrapHeight
import android.widget.TextView; //导入方法依赖的package包/类
/**
* 在某些特定场合下; TextView 的 wrap_content 属性不生效;只好手动设置
* @param textView
* @param tvWidth textView 在屏幕上显示的宽(也就是 textView 父容器赐予的最大宽)
*/
public static void setTvWrapHeight(TextView textView,int tvWidth){
textView.measure(0,0);
int height = textView.getMeasuredHeight();
ViewGroup.LayoutParams params = textView.getLayoutParams();
params.height = height * getRow(textView, tvWidth) ;
textView.setLayoutParams(params);
}
示例9: layoutDebugInfo
import android.widget.TextView; //导入方法依赖的package包/类
private void layoutDebugInfo(final int positionInStrip, final ViewGroup placerView,
final int x) {
final TextView debugInfoView = mDebugInfoViews.get(positionInStrip);
final CharSequence debugInfo = debugInfoView.getText();
if (debugInfo == null) {
return;
}
placerView.addView(debugInfoView);
debugInfoView.measure(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
final int infoWidth = debugInfoView.getMeasuredWidth();
final int y = debugInfoView.getMeasuredHeight();
ViewLayoutUtils.placeViewAt(
debugInfoView, x - infoWidth, y, infoWidth, debugInfoView.getMeasuredHeight());
}
示例10: getTextViewHeight
import android.widget.TextView; //导入方法依赖的package包/类
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();
}