Android seekbar 显示百分比%

将此函数在onDraw函数里调用即可,画笔paint自己初始化一个,根据需求请自行修改

private void drawText(Canvas canvas) {
        int measuredHeight = getMeasuredHeight();
        int measuredWidth = getMeasuredWidth();
        int paddingLeft = getPaddingLeft();
        int i = (measuredWidth - paddingLeft * 2) * getProgress() / getMax();
        String text = getProgress() + "%";
        bounds.setEmpty();
        paint.getTextBounds(text, 0, text.length(), bounds);
        canvas.drawText(text, i + paddingLeft - bounds.width() / 2, measuredHeight / 2.0f + bounds.height() / 2, paint);
    }

猜你喜欢

转载自blog.csdn.net/buyaoshitududongwo/article/details/84227474
今日推荐