Reputation: 21
I call all the mentioned methods right after the onMeasure() of TextView's parent layout returned, like the following:
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int mh = mTextView.getMeasuredHeight();
int h = mTextView.getLineCount() * mTextView.getLineHeight();
}
mh is wrong and shorter than h, does anyone know why, thanks?
Upvotes: 0
Views: 813
Reputation: 24848
// 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();
}
});
Upvotes: 1