• 定义自己的仪表板DashBoard



    既然做了奶站软件,需要使用的仪表板,显示质量数据


    public class MDashboard extends ImageView {



    private Bitmap mPointerBitmap;


    private int max = 100;
    private int progress = 0;


    //构�?

    �?


    public MDashboard(Context context) {
    super(context);
    init();
    }


    public MDashboard(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
    }


    public MDashboard(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    init();
    }
        //初始化布局   Initializes layout
    private void init() {
    setScaleType(ScaleType.FIT_CENTER);
    //设置表盘图片
    setBackgroundDrawableId(R.drawable.base__view_dashboard_bg);
    //设置表针图片Set the dial pictures
    setPointerDrawableId(R.drawable.base__view_dashboard);
      //设置进度,与当前进度Sets the progress and current progress
    setMax(100);
    setProgress(0);
    }


    //设置仪表盘背景Set the dashboard background
    public void setBackgroundDrawableId(int id) {
    setImageResource(id);
    invalidate();
    }
        //设置指针的
    public void setPointerDrawableId(int id) {
    mPointerBitmap = BitmapFactory.decodeResource(getResources(), id);
    invalidate();
    }


    public void setMax(int max) {
    this.max = max;
    invalidate();
    }


    public int getMax() {
    return max;
    }


    public void setProgress(int progress) {
    this.progress = progress;
    //刷新进度
    invalidate();
    }


    public int getProgress() {
    return progress;
    }


    @SuppressLint("DrawAllocation")
    @Override
    protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    int width = this.getWidth();
    int height = this.getHeight();
    int rotate = (int) ((float) ((float) progress / (float) max) * (float) 180);
    Matrix m = new Matrix();
    m.preRotate(rotate);
    Bitmap bitmap = Bitmap.createBitmap(mPointerBitmap, 0, 0,
    mPointerBitmap.getWidth(), mPointerBitmap.getHeight(), m, true);
    int dx = width / 2;
    int dy = height - bitmap.getHeight();
    if (rotate == 90) {
    dx -= bitmap.getWidth() / 2;
    } else if (rotate < 90) {
    dx -= bitmap.getWidth();
    float f = ((float) rotate / (float) 180)
    * (float) mPointerBitmap.getHeight() / 2;
    dx += f;
    } else if (rotate > 90) {
    float f = ((float) rotate / (float) 180)
    * (float) mPointerBitmap.getHeight() / 2;
    dx -= f;
    }
    canvas.drawBitmap(bitmap, dx, dy, null);
    }


    }


    csdn下载   http://download.csdn.net/download/kan1kan5/7816367

    免积分下载 https://github.com/kankanV/KankanDashBoard


    整个代码

    版权声明:本文博客原创文章。博客,未经同意,不得转载。

  • 相关阅读:
    JAVA中分为基本数据类型及引用数据类型
    Tomcat部署HTTPS协议
    MySQL SQL 数据排名查询某条数据是总数据的第几条
    Myeclipse或Eclipse 老是出现JPA project Change Event Handler
    初识Go
    MyBatis xml文件中的大于、小于等符号写法
    jQuery实现5秒倒计时
    JS时间处理由CST格式转成GMT格式时间
    HTML新增加的属性和废除的属性
    HTML 锚点
  • 原文地址:https://www.cnblogs.com/hrhguanli/p/4731241.html
Copyright © 2020-2023  润新知