自定义视图中显示的曲线形状进度 [英] Display curve shape progress in custom View

查看:131
本文介绍了自定义视图中显示的曲线形状进度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与这在圆形自定义视图的工作。几乎我有创建自定义类完成,并实现了。但我的问题是太显示的曲线形状不同的进步与不同的颜色和它是依赖于动态数据。这里是我已经实现了图像

I am working with custom view which is in a circle shape. Almost i have done it with creating a custom class and implemented that. But my problem is too show a different progress in a curve shape with different color and which is depends on dynamic data. Here is the image which i have implemented

我想这样的 http://imgur.com/cmNKWBF

所以我的问题是如何画圆弧(曲线形状)的进展用不同的颜色和动态数据。

So my question is how to draw arc (curve shape) progress with different color and with dynamic data.

帮助将AP preciated !!

Help would be appreciated !!

推荐答案

最后我已经使得自定义 CircleView 类的一些变化后,解决了这个。对于我已经算一个 sweepAngle 由startAngle 为每个区域。这里是code的某些部分我张贴。

Finally i have resolved this after making some changes in Custom CircleView class. For that i have counted a sweepAngle and startAngle for each region. Here is some part of code i am posting.

我必须说明三个不同地区,所以我采取了三种不同的油漆,并宣布每个区域变量。就像,

I had to show three different regions so i have taken three different Paints and declared variable for each regions. Like,

private float   absStart;
private float   absSweep;
private float   preStart;
private float   preSweep;
private float   vacStart;
private float   vacSweep;

private Paint   absPaint;
private Paint   prePaint;
private Paint   vacPaint;

现在您初始化三个地区涂料。在这里,我只是张贴他们中的一个。

Now init your all three regions paints. Here i just posting one of them

absPaint = new Paint();
absPaint.setStrokeCap(Paint.Cap.ROUND);
absPaint.setStyle(Paint.Style.STROKE);
absPaint.setStrokeJoin(Paint.Join.ROUND);
absPaint.setColor(Color.parseColor("#eb537a"));
absPaint.setStrokeWidth((float) 22.5);

现在来计算我已经创建了一个名为方法各区域的面积 updateAngles()这有三个浮动参数

Now to calculate the area of each region i had created a method named updateAngles() which have three float parameters

public void updateAngles(float absPercent, float prePercent, float vacPercent) {
    float total = absPercent + prePercent + vacPercent;
    absStart = 0;
    absSweep = (absPercent / total) * 360;
    preStart = absSweep;
    preSweep = (prePercent / total) * 360;
    vacStart = absSweep + preSweep;
    vacSweep = (vacPercent / total) * 360;

    Log.e("Angles are:", absStart + ":" + absSweep + ":" + preStart + ":" + preSweep + ":" + vacStart + ":" + vacSweep);
    invalidate();
}

这个方法会在你需要的活动被称为初始化后 CircleView ,并呼吁像 cv.updateAngles(20,20,60); ,其中 CV 的对象 CircleView

This method will be called in your desired activity after initialize CircleView and call like cv.updateAngles(20,20,60); where cv is object of CircleView.

现在在的onDraw()方法,你需要画弧为每个区域。

Now in onDraw() method you need to draw arc for each region.

 mInnerRectF.set(45, 45, 330, 330);
 canvas.drawArc(mInnerRectF, absStart, absSweep, false, absPaint);
 canvas.drawArc(mInnerRectF, preStart, preSweep, false, prePaint);
 canvas.drawArc(mInnerRectF, vacStart, vacSweep, false, vacPaint);

因此​​,这终于给了我一个我想要的输出。

So this finally giving me a my desired output.

但如果依赖于像手机屏幕不同的设备,7英寸和10英寸的平板电脑,那么你应该使用 DisplayMetrics 吧。

But if there is depend on different devices like mobile screen , 7 inch and 10 inch tablets then you should use DisplayMetrics for it.

这篇关于自定义视图中显示的曲线形状进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆