获取TextView的高度

来源:互联网 发布:淘宝好的名牌原单店 编辑:程序博客网 时间:2024/05/16 04:32
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();}


Stackoverflow的回答

http://stackoverflow.com/questions/14276853/how-to-measure-textview-height-based-on-device-width-and-font-size

0 0
原创粉丝点击