美文网首页
Android获取控件宽高、获取控件内字体宽高

Android获取控件宽高、获取控件内字体宽高

作者: 程序员文艺范 | 来源:发表于2016-12-15 15:37 被阅读0次
//控件宽高
int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
button.measure(spec, spec);
Log.d(TAG, button.getMeasuredWidth()+"--");
//控件内字宽高
TextPaint textPaint = button.getPaint();
float textPaintWidth = textPaint.measureText(button.getText().toString());
Log.d(TAG, textPaintWidth+"--");

相关文章

网友评论

      本文标题:Android获取控件宽高、获取控件内字体宽高

      本文链接:https://www.haomeiwen.com/subject/ingimttx.html