と、特定の円の外側のゾーン:クリア私が円を充填することによって進捗状況を示すが、今、私は</strong>外にこの白い円を私の見解<strong>のゾーンを消去する方法を探していますカスタムビューを持つキャンバス
ここで、私のコード:
public class CircleGauge extends View {
private int value = 75;
private Paint backgroundPaint, gaugePaint, textPaint, circlePaint;
... constructors
private void init() {
DisplayMetrics metrics = getResources().getDisplayMetrics();
backgroundPaint = new Paint();
backgroundPaint.setColor(ResourcesCompat.getColor(getResources(), R.color.favorite_position_gauge_background, null));
backgroundPaint.setStyle(Paint.Style.FILL);
backgroundPaint.setAntiAlias(true);
gaugePaint = new Paint();
gaugePaint.setColor(ResourcesCompat.getColor(getResources(), R.color.favorite_position_gauge, null));
gaugePaint.setAntiAlias(true);
circlePaint = new Paint();
circlePaint.setColor(Color.WHITE);
circlePaint.setStyle(Paint.Style.STROKE);
circlePaint.setStrokeWidth(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, metrics));
circlePaint.setAntiAlias(true);
textPaint = new Paint();
textPaint.setTextAlign(Paint.Align.CENTER);
textPaint.setColor(Color.WHITE);
textPaint.setFakeBoldText(true);
textPaint.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 23, metrics));
textPaint.setAntiAlias(true);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), backgroundPaint);
canvas.drawRect(0, ((float) (100 - value)/100F) * canvas.getHeight(), canvas.getWidth(), canvas.getHeight(), gaugePaint);
canvas.drawText(getContext().getString(R.string.percent_value, value), getWidth()/2, getHeight() * .6F, textPaint);
canvas.drawCircle(getWidth()/2, getHeight()/2, (getHeight()/2) - circlePaint.getStrokeWidth()/2, circlePaint);
}
public void setValue(int value) {
this.value = value;
invalidate();
}
}
私はかなり確信して私はPorterDuffでこれを行うことができますが、私は方法がわかりません。
は、それが動作し、それはエレガントです、ありがとうございます。私はsetLevel()メソッドを知らなかった –