获取的文本视图高度渲染的布局之前, [英] Getting height of text view before rendering to layout

查看:193
本文介绍了获取的文本视图高度渲染的布局之前,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

找不到什么好的解决办法计算TextView的高度,其中的文本设置之前渲染,用以layout.I搜索很多次,仍然没有result.Any帮助,请

Could not find any good solution calculating textview height where text is setting before rendering to layout.I have searched many times , still there is no result.Any help please

推荐答案

研究的问题solved.Main的事情后,TextView的是在下面的方法,应该设置为我们的TextView应呈现为layout.I觉得这个解决方案是有价值的对于谁遇到这个问题很多人。

After researching the problem was solved.Main thing is TextView in below method should be configured as our TextView which should be rendered to layout.I think this solution is valuable for many people who faced this problem.

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

这篇关于获取的文本视图高度渲染的布局之前,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆