根据百分比(渐变)填充不同颜色的画布空心圆

时间:2014-10-17 08:12:30

标签: android canvas android-progressbar

我试图根据任务完成的百分比设置不同颜色组合的圆圈,但是当我尝试更改颜色时,整个圆圈的颜色似乎发生了变化,如果任何人都可以指导我朝着正确的方向前进 以下是Canvas类绘制方法

@Override
protected synchronized void onDraw(Canvas canvas) {             
    canvas.drawArc(mCircleBounds, 110, 320 , false, mBackgroundColorPaint);     
    int prog = getProgress();
    float scale = getMax() > 0 ? (float)prog/getMax() *320: 0;
    if(mHasShadow)
        mProgressColorPaint.setShadowLayer( 3, 0, 1, mShadowColor);

    canvas.drawArc(mCircleBounds, 110, scale , false, mProgressColorPaint);

    if(!TextUtils.isEmpty(mTitle)){
        int xPos =  (int)(getMeasuredWidth()/2 - mTitlePaint.measureText(mTitle) / 2);
        int yPos = (int) (getMeasuredHeight()/2);   

        float titleHeight = Math.abs(mTitlePaint.descent() + mTitlePaint.ascent());
        if(TextUtils.isEmpty(mSubTitle)){
            yPos += titleHeight/2;
        }
        canvas.drawText(mPercentageIndicator, xPos, yPos, mSubtitlePaint);      
    }   
    super.onDraw(canvas);
}

以下是style.xml的链接

<style name="Widget.ProgressBar.CircularProgressBar" parent="Widget">
    <item name="hasShadow">true</item>
    <item name="strokeWidth">55</item>       
    <item name="PercentageCounter"></item>
    <item name="subtitle"></item>
</style>

请帮助我完成这个:(任何帮助都会得到赞赏,或指导我正确的方向,谢谢

0 个答案:

没有答案