• Android自定义进度条-带文本(文字进度)的水平进度条(ProgressBar)


    /** 
     * 带文本提示的进度条 
     */
    public class TextProgressBar extends ProgressBar { 
        private String text; 
        private Paint mPaint; 
      
        public TextProgressBar(Context context) { 
            super(context); 
            initText(); 
        } 
      
        public TextProgressBar(Context context, AttributeSet attrs, int defStyle) { 
            super(context, attrs, defStyle); 
            initText(); 
        } 
      
        public TextProgressBar(Context context, AttributeSet attrs) { 
            super(context, attrs); 
            initText(); 
        } 
      
        @Override
        public void setProgress(int progress) { 
            setText(progress); 
            super.setProgress(progress); 
      
        } 
      
        @Override
        protected synchronized void onDraw(Canvas canvas) { 
            super.onDraw(canvas); 
            Rect rect = new Rect(); 
            this.mPaint.getTextBounds(this.text, 0, this.text.length(), rect); 
            int x = (getWidth() / 2) - rect.centerX(); 
            int y = (getHeight() / 2) - rect.centerY(); 
            canvas.drawText(this.text, x, y, this.mPaint); 
        } 
      
        // 初始化,画笔 
        private void initText() { 
            this.mPaint = new Paint(); 
            this.mPaint.setAntiAlias(true); 
            this.mPaint.setColor(Color.WHITE); 
      
        } 
      
        // 设置文字内容 
        private void setText(int progress) { 
            int i = (int) ((progress * 1.0f / this.getMax()) * 100); 
            this.text = String.valueOf(i) + "%"; 
        } 
    }
  • 相关阅读:
    BZOJ 1218: [HNOI2003]激光炸弹( 前缀和 + 枚举 )
    BZOJ 1878: [SDOI2009]HH的项链( BIT )
    BZOJ 1054: [HAOI2008]移动玩具( BFS )
    js-提取行间元素
    vim的三种模式的基本操作
    Linux的高级命令
    Linux的进阶命令
    Linux的基本命令
    Linux常见的文件目录结构
    js-操作属性
  • 原文地址:https://www.cnblogs.com/linximeng/p/3753108.html
Copyright © 2020-2023  润新知