• 定义自己的仪表板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


    整个代码

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

  • 相关阅读:
    (二)、一步一步学GTK+之窗口
    phpcms v9 评论的bug.
    为discuz x2.5添加播放附件(mp4)的方法
    code::blocks + C + lua 编译环境
    C语言从声卡录音的一个demo
    泛型集合(.NET 2.0)
    VS2008对ASP.NET引用的外部JS文件不能调试
    for循环和foreach
    CSS之DIV上下左右居中
    GridView控件相关(来自互联网)
  • 原文地址:https://www.cnblogs.com/hrhguanli/p/4731241.html
Copyright © 2020-2023  润新知