@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());这句话屌啊,把字体的高度也算进去了

android 设置自定义控件的区域onMeasure(int widthMeasureSpec, int hei



相关文章:

  • 2022-12-23
  • 2021-12-18
  • 2021-11-04
  • 2022-12-23
  • 2022-12-23
  • 2021-08-28
  • 2022-12-23
  • 2022-01-07
猜你喜欢
  • 2021-11-22
  • 2022-12-23
  • 2021-12-02
  • 2022-12-23
  • 2021-06-08
  • 2021-10-07
  • 2022-12-23
相关资源
相似解决方案