Android seekbar 顯示百分比%
阿新 • • 發佈:2018-12-22
將此函式在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); }