zoukankan      html  css  js  c++  java
  • 安卓带百分比的进度条显示

    继承进度条代码:
    import android.content.Context;
    import android.graphics.Canvas;
    import android.graphics.Color;
    import android.graphics.Paint;
    import android.graphics.Rect;
    import android.util.AttributeSet;
    import android.widget.ProgressBar;

    public class PecentProgress extends ProgressBar {

    String text;
    Paint Paint;


    public PecentProgress(Context context) {
    super(context);
    // TODO Auto-generated constructor stub
    System.out.println("1");
    initText();
    }

    public PecentProgress(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    // TODO Auto-generated constructor stub
    System.out.println("2");
    initText();
    }


    public PecentProgress(Context context, AttributeSet attrs) {
    super(context, attrs);
    // TODO Auto-generated constructor stub
    System.out.println("3");
    initText();
    }

    @Override
    public synchronized void setProgress(int progress) {
    // TODO Auto-generated method stub
    setText(progress);
    super.setProgress(progress);

    }

    @Override
    protected synchronized void onDraw(Canvas canvas) {
    // TODO Auto-generated method stub
    super.onDraw(canvas);
    //this.setText();
    Rect rect = new Rect();
    this.Paint.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.Paint);
    }

    //初始化
    private void initText(){
    this.Paint = new Paint();
    this.Paint.setColor(Color.BLUE);

    }

    private void setText(){
    setText(this.getProgress());
    }

    //设置文字内容
    private void setText(int progress){
    int i = (progress * 100)/this.getMax();
    this.text = String.valueOf(i) + "%";
    }



    }

    页面代码
    <com.example.utils.PecentProgress 上面精度条继承类所在的包
    android:id="@+id/load_proj_bar"
    android:max="100"
    android:layout_gravity="center"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_heightPercent="80%" //安卓百分比
    app:layout_widthPercent="90%"
    style="@android:style/Widget.ProgressBar.Horizontal"
    android:visibility="visible"
    />

    //初始化

    private PecentProgress progress = null;
    pros = (PecentProgress ) findViewById(R.id.load_proj_bar);

    //开启子线程,设置进度条
    pros .setMax(100);
    pros .setProgress(0);




  • 相关阅读:
    代理(reGeorg)
    弱口令爆破技巧
    无法解析@NotBlank
    LC 1723. Find Minimum Time to Finish All Jobs (dp+二分)
    帝国cms 联合多张表查询
    php 根据白名单替换字符转中的链接 封装的函数
    php 正则匹配域名后的整个链接和只匹配域名
    JVM系列(一):垃圾回收之MinorGC,MajorGC和FullGC的区别
    spring事务的执行原理
    java基础系列(八):Semphore,CountDownLatch和CyclicBarrier的使用
  • 原文地址:https://www.cnblogs.com/dosoftwarey/p/11573792.html
Copyright © 2011-2022 走看看