Android获取控件宽高、获取控件内字体宽高
2016-12-15 本文已影响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+"--");