@Override protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int heightMode = MeasureSpec.getMode(heightMeasureSpec); int widthMode = MeasureSpec.getMode(widthMeasureSpec); // if (widthMode == MeasureSpec.AT_MOST) { // int a = 0; // } if (heightMode != MeasureSpec.EXACTLY) { float textHeight = (mPaint.descent() + mPaint.ascent()); int exceptHeight = (int) (getPaddingTop() + getPaddingBottom() + Math .max(Math.max(mReachedProgressBarHeight, mUnReachedProgressBarHeight), Math.abs(textHeight * 2))); heightMeasureSpec = MeasureSpec.makeMeasureSpec(exceptHeight, MeasureSpec.EXACTLY); //宽度 int width = getScreenWidth(); widthMeasureSpec = MeasureSpec.makeMeasureSpec(width,MeasureSpec.EXACTLY); } super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
float textHeight = (mPaint.descent() + mPaint.ascent());这句话屌啊,把字体的高度也算进去了