2

円弧状のプログレスバーを作成する必要があります。そのためのカスタムビューを作成する必要がありますか?または、onDraw()ProgressBarクラスのメソッドを使用して、このことを実行できますか?また、温度計のようにこのプログレスバーにマーカーを追加したいと思います。何かアイデアを教えてください。ありがとう。

このようなもの:

protected synchronized void onDraw(Canvas canvas) {

    int progress = this.getProgress();
    int maxProgress = this.getMax();

    //calc the progress to angles 
    float angleProgress = progress * 360 / maxProgress;

    //create and set the arc paint 
    Paint arcPaint = new Paint(); 
    arcPaint.setColor(0xff800000); 
    arcPaint.setAntiAlias(true); 
    arcPaint.setStyle(Style.FILL);

    Rect arcRect = new Rect(); this.getDrawingRect(arcRect);
    canvas.drawArc(new RectF(arcRect), -90, angleProgress,true, arcPaint); 
}

参照については、この画像の円弧形状のプログレスバーを確認してください http://i.stack.imgur.com/FY0dq.png

4

1 に答える 1

1

デフォルトのProgressBarウィジェットは、これよりも大幅に野心的な変更がない場合でも、簡単にカスタマイズすることはできません。私の意見では、最小値、最大値、および現在の値のキャリアとして機能する以外に、このコンテキストでの価値のある動作は提供されません。また、「不確定」状態などの不要な機能ももたらします。

Viewを拡張し、onDraw()とonMeasure()を実装して、カスタムビューを作成します。

于 2012-02-06T11:42:25.150 に答える