我有这段代码可以测量文本宽度。
public float textWidthPixels(String text) {
TextPaint textPaint = myAccountView.getPaint();
float width = textPaint.measureText(text);
View parent = (View) myAccountView.getParent();
int paddingLeft = parent.getPaddingLeft();
int paddingRight = parent.getPaddingRight();
return width - (paddingLeft + paddingRight);
}
,从
调用final ViewTreeObserver[] viewTreeObserver = {myAccountView.getViewTreeObserver()};
viewTreeObserver[0].addOnPreDrawListener(
new OnPreDrawListener() {
@Override
public boolean onPreDraw() {
但是
当我在辅助功能菜单中将字体大小更改为大字体时,
文本宽度变化但不准确(它表示文本宽度小于其所在的视图,但实际上大于视图)