Java Code Examples for android.widget.TextView.getMeasuredHeight()

The following are Jave code examples for showing how to use getMeasuredHeight() of the android.widget.TextView class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: aos-MediaLib   File: ArtworkFactory.java   View Source Code Vote up 6 votes
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);
}
 
Example 2
Project: cnBetaGeek   File: CommentsView.java   View Source Code Vote up 5 votes
/**
 * 在绘制之前,测量 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();
}
 
Example 3
Project: Bailan   File: FoldingTextView.java   View Source Code Vote up 5 votes
/**
 * 要伸缩文本的高度 宽度固定的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();
}
 
Example 4
Project: Bailan   File: FoldingTextView.java   View Source Code Vote up 5 votes
/**
 * 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();
}
 
Example 5
Project: MyLife   File: TextViewUtils.java   View Source Code Vote up 5 votes
/**
 * 获取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();
}
 
Example 6
Project: Hotspot-master-devp   File: AlignTextView.java   View Source Code Vote up 5 votes
/**
 * 获取文本实际所占高度,辅助用于计算行高,行数
 *
 * @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();
}
 
Example 7
Project: editor-sql   File: Utils.java   View Source Code Vote up 5 votes
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;
}
 
Example 8
Project: AdaptationX-android   File: TextViewManager.java   View Source Code Vote up 5 votes
/**
 * 在某些特定场合下; 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);
}
 
Example 9
Project: AOSP-Kayboard-7.1.2   File: SuggestionStripLayoutHelper.java   View Source Code Vote up 5 votes
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());
}
 
Example 10
Project: MyFire   File: GoodView.java   View Source Code Vote up 4 votes
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();
}
 
Example 11
Project: Renrentou   File: GoodView.java   View Source Code Vote up 4 votes
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();
}
 
Example 12
Project: RLibrary   File: GoodView.java   View Source Code Vote up 4 votes
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();
}