//控件宽高
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+"--");
网友评论