我在TextView的父布局的onMeasure()返回后立即调用所有提到的方法,如下所示:
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int mh = mTextView.getMeasuredHeight();
int h = mTextView.getLineCount() * mTextView.getLineHeight();
}
mh错误且比h短,有谁知道原因,谢谢?
答案 0 :(得分:1)
// Try this way,hope this will help you to solve your problem...
mTextView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int mh = mTextView.getMeasuredHeight();
int h = mTextView.getLineCount() * mTextView.getLineHeight();
}
});